HELLO I WANT TO ADD A BUTTON UNDER THA TABLE I HAVE CREATE!! ANY IDEAS PLEASEEE....THANKS!!
HERE IS MY CODE
import javax.swing.table.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class Buy extends Items {
public int countLines(String filename){
int lines = 0; //mporei na metrhsei mexri "int" grammes (~2.1 dis grammes)
try {
// Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream(filename);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
lines++;//metrhths grammwn/eggrafwn
}
//close input stream
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
return lines;}
public String[] showAllRegisteredItems(String filename, int size) {
String[] temp = new String[size+1]; //mexri "size" kataxwrhseis ma8hmatwn dld (mege8os "int")
try {
int x = 0;
// Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream(filename);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
//System.out.println(strLine.replace("#", " "));
temp[x] = strLine;
x++;
}
//close input stream
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
return temp;
}
public JPanel pinakas(String[] pinaka){
int sr = 0;
//int ari8mos =0;
String[] COLUMN_NAMES = {"Κωδικός", "Ποσότητα", "Τιμή", "Περιγραφή", "Μέγεθος", "Ράτσα"};
//pio panw mporoume na pros8esoume ws prwto column to "#", wste na deixnei ton ari8mo ths ka8e kataxwrhshs
DefaultTableModel modelM = new DefaultTableModel(COLUMN_NAMES, 0);
JTable tableM = new JTable(modelM);
JPanel mainPanel = new JPanel(new BorderLayout());
JButton button1 = new JButton("Button Text");
mainPanel.add(new JScrollPane(tableM),BorderLayout.CENTER);
mainPanel.add(button1);
// Install a button renderer in the last column
Display disp = new Display();
while (pinaka[sr] != null) // !!!!tha ektupwsei kai mia parapanw "/n" logo ths kataxwrhshs prwtou h teleytaiou mahmatos
{
String[] temp5 = disp.lineDelimiter(pinaka[sr],6, "#");
Object[] doge = { temp5[0], temp5[1], temp5[2], temp5[3], temp5[4], temp5[5]};//edw mporoume sthn arxh na valoume to ari8mos gia na fainetai o ari8mos twn kataxwrhsewn
modelM.addRow(doge);
sr++;
//ari8mos++;
}
return mainPanel;
}
public static void main(String[] args) {
Display disp= new Display();
Dogs dog=new Dogs();
int numberofline=disp.countLines("Dogss.txt");
String[] tempΜ1 = disp.showAllRegisteredItems("Dogss.txt",numberofline);
JOptionPane.showMessageDialog(null, dog.pinakas(tempΜ1), "Καταχωρημένα Kατοικίδια", JOptionPane.PLAIN_MESSAGE);
}
}
HERE IS MY CODE
import javax.swing.table.*;
import java.awt.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
public class Buy extends Items {
public int countLines(String filename){
int lines = 0; //mporei na metrhsei mexri "int" grammes (~2.1 dis grammes)
try {
// Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream(filename);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
lines++;//metrhths grammwn/eggrafwn
}
//close input stream
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
return lines;}
public String[] showAllRegisteredItems(String filename, int size) {
String[] temp = new String[size+1]; //mexri "size" kataxwrhseis ma8hmatwn dld (mege8os "int")
try {
int x = 0;
// Open the file that is the first command line parameter
FileInputStream fstream = new FileInputStream(filename);
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
//System.out.println(strLine.replace("#", " "));
temp[x] = strLine;
x++;
}
//close input stream
} catch (Exception e) {//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
return temp;
}
public JPanel pinakas(String[] pinaka){
int sr = 0;
//int ari8mos =0;
String[] COLUMN_NAMES = {"Κωδικός", "Ποσότητα", "Τιμή", "Περιγραφή", "Μέγεθος", "Ράτσα"};
//pio panw mporoume na pros8esoume ws prwto column to "#", wste na deixnei ton ari8mo ths ka8e kataxwrhshs
DefaultTableModel modelM = new DefaultTableModel(COLUMN_NAMES, 0);
JTable tableM = new JTable(modelM);
JPanel mainPanel = new JPanel(new BorderLayout());
JButton button1 = new JButton("Button Text");
mainPanel.add(new JScrollPane(tableM),BorderLayout.CENTER);
mainPanel.add(button1);
// Install a button renderer in the last column
Display disp = new Display();
while (pinaka[sr] != null) // !!!!tha ektupwsei kai mia parapanw "/n" logo ths kataxwrhshs prwtou h teleytaiou mahmatos
{
String[] temp5 = disp.lineDelimiter(pinaka[sr],6, "#");
Object[] doge = { temp5[0], temp5[1], temp5[2], temp5[3], temp5[4], temp5[5]};//edw mporoume sthn arxh na valoume to ari8mos gia na fainetai o ari8mos twn kataxwrhsewn
modelM.addRow(doge);
sr++;
//ari8mos++;
}
return mainPanel;
}
public static void main(String[] args) {
Display disp= new Display();
Dogs dog=new Dogs();
int numberofline=disp.countLines("Dogss.txt");
String[] tempΜ1 = disp.showAllRegisteredItems("Dogss.txt",numberofline);
JOptionPane.showMessageDialog(null, dog.pinakas(tempΜ1), "Καταχωρημένα Kατοικίδια", JOptionPane.PLAIN_MESSAGE);
}
}