I am trying to make a program that I enter first name and last name and so on and then being about to view that information again.
I am using Java and Jframes
i have setup my interface with JTextfileds and Jlabels and a button
i am trying to make an array of objects so each array number will contain (firstname, lastname , and so on) and then i am going to print it out into a Jlist. i want to make it so when i prees my button it will input everything in my Jtextinputs in the first array
but i don't know how to do the array with objects i have started one but i need help thanks
i know that i need to use
ArrayList<> mylist = new ArrayList<Data>();
Data myTask = new Data("imput", "input");
myList.add(myTask);
But I don't understand how I use it
Thanks
that is my data.java file
package components;
Import Java.Io.Serializable;
public class Data implements Serializable {
static final long serialVersionUID = 1;
String name;
String description;
public Task(String Fname, String Lname) {
this.name = Fname;
this.description = Lname;
}
public String getName() {
return this.name;
}
public String getDescription() {
Return this.description;
}
interface file
public class DataDemo extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
//Name Label and TextField
protected static JLabel LbName;
protected static JTextField txtInputName;
//Description Label and TextField
protected static JLabel LbDescription;
protected static JTextField txtInputDescription;
//Submit Button
static JButton btnSubmit;
@SuppressWarnings("unchecked")
public DataDemo() {
//Name Label and TextField
LbName = new JLabel("Name:");
txtInputName = new JTextField(200);
//Description Label and TextField
LbDescription = new JLabel("Description:");
txtInputDescription = new JTextField(20);
//Submit Button
btnSubmit = new JButton("Done");
btnSubmit.addActionListener(this);
//Add Components to this container, using the default FlowLayout.
setLayout(null);
//Name
add(LbName);
add(txtInputName);
//Description
add(LbDescription);
add(txtInputDescription);
//button Submit
add(btnSubmit);
}
public void actionPerformed(ActionEvent event) {
if (event.getSource() == btnSubmit)
}
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("DataDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
DataDemo newContentPane = new DataDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setSize(500, 500);
frame.setVisible(true);
//(x,y,with,height)
//Name interface position
LbName.setBounds(50, 70, 200, 25);
txtInputName.setBounds(200, 70, 200, 25);
//Description interface position
LbDescription.setBounds(50, 100, 200, 25);
txtInputDescription.setBounds(200, 100, 200, 25);
//button Submit
btnSubmit.setBounds(200, 150, 200, 25);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}