This is my first question from stock overflow exited a bit I have made a class and JTextField
for a class and I have a problem once I click the complete order Button it should save all the data and information nice and cool in JTable
I have been thought to use String[]
and Object
but basically I have no Idea how to do it ???
and this is my software class
class Software extends Products {
private float ram;
private float processor;
//SoftwareProducts sf = new SoftwareProducts();
public Software(int productID, String productName,
int productYear, String productPublishHouse) {
super(productID, productName, productYear, productPublishHouse);
this.ram = ram;
this.processor = processor;
//super(productID,productName, productYear, productPublishHouse);
}
public void setRam(float ram) {
this.ram = ram;
}
public float getRam() {
return ram;
}
public void setProcessor(float processor) {
this.processor = processor;
}
public float getProcessor() {
return processor;
}
}
//int productID,String productName,int productYear,
String productPublishHouse
and this is my Customer Order Class which Basically I need to run my JTable from it and make String and Object
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.io.*;
public class CustomerOrder extends JPanel
implements ActionListener {
//JButton asd = new JButton("BUTTON");
//JTextField productID;
//JTextField productName;
//JTextField productCost;
//JTextField productPYear;
//JTextField productPHouse;
JButton showOrder;
DefaultListModel<String> model = new DefaultListModel<>();
JList<String> orderList = new JList(model);
JTable softwareTabel = new JTable();
//DefaultTableModel tableModel = new DefaultTableModel(0, 1);
public CustomerOrder() {
//super();
// JLabel toLabel=new JLabel("Product ID: ");
//JTextField to=new JTextField();
setLayout(new FlowLayout());
/*
productName = new JTextField(12);
add(productName);
productCost = new JTextField(12);
add(productCost);
productPYear = new JTextField(12);
add(productPYear);
productPHouse = new JTextField(12);
add(productPHouse);
*/
showOrder = new JButton("SHOW ORDER");
showOrder.setSize(25, 40);
showOrder.addActionListener(this);
add(showOrder);
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == showOrder) {
model.removeAllElements();
/* GridLayout exLayout = new GridLayout(3, 3);
JLabel ram,processor;
ram = new JLabel("RAM");
processor = new JLabel("Processor");
String softwaredata[] = {"ID","RAM","Processor","Product ID","Product Name","Product Year","Product Year","Product PublishHouse"};
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(8, 3));
add(ram);
add(processor);
JTable table = new JTable();*/
//DeafultTableModel dm = new DeafultTableModel(0,0);
//String header[] = new String[] {"RAM", "Processor","ProductID","Product Name","Product Year","Product Publish House"};
//dm.setColumnIdentifiers(header);
//Object[][] software = new Object[8][3];
//model.addRow(orderList.toArray());
int x = 0;
while (x < main.softwareList.size()) {
//./model.addElement(main.softwareList.get(x).getproductYear());
model.addElement("" + main.softwareList.get(x).getproductID());
model.addElement("" + main.softwareList.get(x).getRam());
model.addElement("" + main.softwareList.get(x).getProcessor());
model.addElement("" + main.softwareList.get(x).getproductID());
model.addElement(main.softwareList.get(x).getproductName());
model.addElement("" + main.softwareList.get(x).getproductYear());
model.addElement(main.softwareList.get(x).getproductPublishHouse());
//model.addElement(main.softwareList.get(x).getproductID());*/
x++;
//System.out.println("as");
}
ArrayList<String> table1 = new ArrayList();
ArrayList<ArrayList<String>> table2 = new ArrayList();
table1.add("Product ID");
table1.add("RAM");
table1.add("Processor");
table1.add("Product Name");
table1.add("Product Year");
table1.add("Product PHouse");
Object[] software = table1.toArray();
String[][] softwarest = new String[table1.size()][];
int i = 0;
for (List<String> next : table2) {
softwarest[i++] = next.toArray(new String[next.size()]);
}
JTable newTable = new JTable(softwarest, software);
JFrame frame = new JFrame();
frame.getContentPane().add(new JScrollPane(newTable));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//add(model);
add(orderList);
//Object[] column = {"RAM:", "Processor:"};
//Object[][] data = {{"RAM:", "Processor:"}};
//JTable table = new JTable();
//table.setShowGrid(false);
//table.setTableHeader(null);
}
}
}