How can I show JDialog generated with JFormDesigner - jdialog

I generated a JDialog w/ JFormDesigner, but I don't know how to display it. Here is the code:
public class FinishPopup extends JDialog {
public FinishPopup(Frame owner) {
super(owner);
initComponents();
}
public FinishPopup(Dialog owner) {
super(owner);
initComponents();
}
public void initComponents() {
dialogPane = new JPanel();
contentPanel = new JPanel();
label1 = new JLabel();
label2 = new JLabel();
buttonBar = new JPanel();
okButton = new JButton();
label3 = new JLabel();
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
{
{
label1.setText("Money: ");
label1.setFont(new Font("Tahoma", Font.PLAIN, 12));
label2.setText("Time");
label2.setFont(new Font("Tahoma", Font.PLAIN, 12));
GroupLayout contentPanelLayout = new GroupLayout(contentPanel);
contentPanel.setLayout(contentPanelLayout);
contentPanelLayout.setHorizontalGroup(
contentPanelLayout.createParallelGroup()
.addGroup(contentPanelLayout.createSequentialGroup()
.addContainerGap()
.addComponent(label2)
.addGap(90, 90, 90)
.addComponent(label1)
.addContainerGap(105, Short.MAX_VALUE))
);
contentPanelLayout.setVerticalGroup(
contentPanelLayout.createParallelGroup()
.addGroup(contentPanelLayout.createSequentialGroup()
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(contentPanelLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(label2)
.addComponent(label1))
.addContainerGap())
);
}
dialogPane.add(contentPanel, BorderLayout.CENTER);
{
buttonBar.setBorder(new EmptyBorder(12, 0, 0, 0));
buttonBar.setLayout(new GridBagLayout());
((GridBagLayout)buttonBar.getLayout()).columnWidths = new int[] {0, 80};
((GridBagLayout)buttonBar.getLayout()).columnWeights = new double[] {1.0, 0.0};
okButton.setText("OK");
buttonBar.add(okButton, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
GridBagConstraints.CENTER, GridBagConstraints.BOTH,
new Insets(0, 0, 0, 0), 0, 0));
}
dialogPane.add(buttonBar, BorderLayout.SOUTH);
label3.setText("Finished");
label3.setFont(new Font("Tahoma", Font.BOLD, 14));
dialogPane.add(label3, BorderLayout.NORTH);
}
contentPane.add(dialogPane, BorderLayout.CENTER);
pack();
setLocationRelativeTo(getOwner());
}
private JPanel dialogPane;
private JPanel contentPanel;
private JLabel label1;
private JLabel label2;
private JPanel buttonBar;
private JButton okButton;
private JLabel label3;
}
How do I create and show it? thanks.

You need to first create an instance of the class and then call setVisible to make it visible
// owner is reference to the parent frame or dialog. May be null, but you'll
// need to cast it
FinishPopup popup = new FinishPopup(owner);
popup.setVisible(true);
You may also find setLocationRelativeTo helpful

Related

wxWidgets. Creating a new page within wxAuiNotebook on command

How do I add a page to wxAUINoteBook? I wish to be able to click: File->New, and then have a new tab pop in. I understand how to do this using wxAuiMDIChildFrame within a parent frame but the child frame is a class on its own and a new page is not. Here is what I have so far.
#include "main.h"
MyFrame::MyFrame()
: wxFrame(nullptr, wxID_ANY, "AUItest", wxPoint(50, 50), wxSize(800, 450), wxDEFAULT_FRAME_STYLE)
{
wxMenuBar* menubar = new wxMenuBar;
wxMenu* menufile = new wxMenu;
menufile->Append(1001, "New");
menufile->Append(1002, "Open");
menufile->Append(1003, "Save");
menufile->Append(1004, "Exit");
menubar->Append(menufile, "File");
SetMenuBar(menubar);
wxAuiNotebook* notebook = new wxAuiNotebook(this, -1, wxPoint(-1, -1),
wxSize(-1, -1), wxNB_TOP | wxAUI_NB_CLOSE_ON_ACTIVE_TAB);
wxPanel* panel1 = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
wxPanel* panel2 = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
wxPanel* panel3 = new wxPanel(notebook, wxID_ANY, wxDefaultPosition, wxDefaultSize);
notebook->AddPage(panel1, wxT("Sheet1"));
notebook->AddPage(panel2, wxT("Sheet2"));
notebook->AddPage(panel3, wxT("Sheet3"));
Center();
}
MyFrame::~MyFrame()
{
}
wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(1001, MyFrame::OnMenuNew)
EVT_MENU(1002, MyFrame::OnMenuOpen)
EVT_MENU(1003, MyFrame::OnMenuSave)
EVT_MENU(1004, MyFrame::OnMenuExit)
wxEND_EVENT_TABLE()
void MyFrame::OnMenuNew(wxCommandEvent& event)
{
//How do I add a page on command?
}
void MyFrame::OnMenuOpen(wxCommandEvent& event)
{
}
void MyFrame::OnMenuSave(wxCommandEvent& event)
{
}
void MyFrame::OnMenuExit(wxCommandEvent& event)
{
Close(true);
event.Skip();
}
Thanks for the help,
I'm still learning.

How to get an item from an array list of objects

So what do I do to "open" my array list of Appointment objects?
I have tried iteration but it gets 2 correct displays, or repeats the last entry. I need to set the text fields to a variable inside an array of objects. How do I go about that? This a calendar that saves your appointments into an array list the catch that the list is of an object type called appointments. I am so close to finishing I just can not get what to do with displaying or setting the information into the text fields.
import java.awt.Color;
import java.util.*;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
public class Calendario extends Application {
private TextField s = new TextField();
private TextField m = new TextField();
private TextField t = new TextField();
private TextField w = new TextField();
private TextField th = new TextField();
private TextField f = new TextField();
private TextField st = new TextField();
private TextField dom = new TextField();
private TextField lun = new TextField();
private TextField mar = new TextField();
private TextField mie = new TextField();
private TextField hue = new TextField();
private TextField vir = new TextField();
private TextField sab = new TextField();
private Label firstd = new Label("Sunday");
private Label secd = new Label("Monday");
private Label thrd = new Label("Tuesday");
private Label fortd = new Label("Wednesday");
private Label fiftd = new Label("Thursday");
private Label sistd = new Label("Friday");
private Label svnd = new Label("Saturday");
private Button submit = new Button();
private Button open = new Button();
private Button clear = new Button();
private ArrayList<Appointment> date = new ArrayList<Appointment>();
public class Appointment{
DayOfWeek day;
String tiempo;
String d;
Appointment(String tiempo,String d){
if(Character.isDigit(tiempo.charAt(0)) && tiempo.endsWith("a") ||
tiempo.endsWith("p")){
this.tiempo = tiempo;
}
else{
throw new IllegalArgumentException("First input must be numeric and a for am"+
"p for pm");
}
this.d = d;
}
}
public void submit(){
for (DayOfWeek day : DayOfWeek.values()){
switch (day){
case SUNDAY:
Appointment sunday = new Appointment(s.getText(),dom.getText());
date.add(sunday);
break;
case MONDAY:
Appointment monday = new Appointment(m.getText(),lun.getText());
date.add(monday);
break;
case TUESDAY:
Appointment tuesday = new Appointment(t.getText(),mar.getText());
date.add(tuesday);
break;
case WEDNESDAY:
Appointment wednesday = new Appointment(w.getText(),mie.getText());
date.add(wednesday);
break;
case THURSDAY:
Appointment thursday = new Appointment(th.getText(),hue.getText());
date.add(thursday);
break;
case FRIDAY:
Appointment friday = new Appointment(f.getText(),vir.getText());
date.add(friday);
break;
case SATURDAY:
Appointment saturday = new Appointment(st.getText(),sab.getText());
date.add(saturday);
break;
default:
System.out.println("Error oh no help master");
break;
}
}
}
public void open(){
}
public void clear(){
date.clear();
}
#Override
public void start(Stage primaryStage) {
submit.setText("Submit");
submit.setStyle("-fx-background-color: #00ff00");
submit.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
submit();
}
});
open.setText("Open");
open.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
open();
}
});
clear.setText("Clear");
clear.setStyle("-fx-background-color: #ff0000");
clear.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
clear();
}
});
HBox frame = new HBox();
VBox sun = new VBox(10);
VBox mon = new VBox(10);
VBox tues = new VBox(10);
VBox wed = new VBox(10);
VBox thur = new VBox(10);
VBox fri = new VBox(10);
VBox sat = new VBox(10);
sun.getChildren().addAll(firstd,s,dom);
mon.getChildren().addAll(secd,m,lun);
tues.getChildren().addAll(thrd,t,mar);
wed.getChildren().addAll(fortd,w,mie);
thur.getChildren().addAll(fiftd,th,hue,clear);
fri.getChildren().addAll(sistd,f,vir,open);
sat.getChildren().addAll(svnd,st, sab,submit);
firstd.setTranslateX(20);
secd.setTranslateX(20);
thrd.setTranslateX(20);
fortd.setTranslateX(10);
fiftd.setTranslateX(20);
sistd.setTranslateX(20);
svnd.setTranslateX(20);
frame.getChildren().addAll(sun,mon,tues,wed,thur,fri,sat);
Scene scene = new Scene(frame, 600, 300);
primaryStage.setTitle("Appoinment Calendar");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
The code is not well written. Just consider how similar the code for all the days is. Why repeat yourself instead of coming up with a suitable data structure that allows you to access the objects more conveniently? Why create 2 x 7 TextFields when you can create 2 and use a loop to repeat the process?
One more thing you need to do is actually store the day of the week in you Appointment.
The open implementation in the following code assumes the content of the date list already contains the proper values even though currently the code only restores the last submitted values, if the user edits the TextFields.
private ArrayList<Appointment> date = new ArrayList<Appointment>();
public static class Appointment {
final DayOfWeek day;
final String tiempo;
final String d;
Appointment(String tiempo, String d, DayOfWeek day) {
if (Character.isDigit(tiempo.charAt(0)) && tiempo.endsWith("a") || tiempo.endsWith("p")) {
this.tiempo = tiempo;
} else {
throw new IllegalArgumentException("First input must be numeric and a for am" + "p for pm");
}
this.d = d;
this.day = day;
}
}
public void submit() {
// add appointment for each entry in the map
inputs.forEach((day, inputs) -> {
date.add(new Appointment(inputs[0].getText(), inputs[1].getText(), day));
});
}
public void open() {
// clear fields
inputs.values().stream().flatMap(Arrays::stream).forEach(TextField::clear);
// set text for all elements of date
date.forEach(appointment -> {
TextField[] fields = inputs.get(appointment.day);
fields[0].setText(appointment.tiempo);
fields[1].setText(appointment.d);
});
}
public void clear() {
date.clear();
}
private final Map<DayOfWeek, TextField[]> inputs = new EnumMap<>(DayOfWeek.class);
#Override
public void start(Stage primaryStage) {
Button submit = new Button("Submit");
submit.setStyle("-fx-background-color: #00ff00");
submit.setOnAction(event -> submit());
Button open = new Button("Open");
open.setOnAction(event -> open());
Button clear = new Button("Clear");
clear.setStyle("-fx-background-color: #ff0000");
clear.setOnAction(event -> clear());
GridPane grid = new GridPane();
grid.setVgap(10);
Locale locale = Locale.ENGLISH;
TextStyle textStyle = TextStyle.FULL;
Insets headerMargin = new Insets(0, 0, 0, 20);
// add inputs and label for days starting with sunday and store inputs in map
for (int i = 0; i < 7; i++) {
DayOfWeek day = DayOfWeek.SUNDAY.plus(i);
Label label = new Label(day.getDisplayName(textStyle, locale));
GridPane.setMargin(label, headerMargin);
TextField timeField = new TextField();
TextField dField = new TextField();
inputs.put(day, new TextField[] { timeField, dField });
grid.addColumn(i, label, timeField, dField);
}
HBox buttonContainer = new HBox(10, clear, open, submit);
buttonContainer.setAlignment(Pos.TOP_RIGHT);
VBox.setMargin(buttonContainer, new Insets(0, 20, 0, 0));
VBox root = new VBox(10, grid, buttonContainer);
Scene scene = new Scene(root, 600, 300);
primaryStage.setTitle("Appoinment Calendar");
primaryStage.setScene(scene);
primaryStage.show();
}

Correct way to serialize a JPanel?

I am sending my class which extends JPanel through an ObjectOutputStream to the client, so that their GUI will 'load'.
public class ClickOptionPanel extends JPanel implements Serializable {
private Font font = new Font("Arial", Font.BOLD, 13);
private JLabel clickerTitle;
private JSlider clickerMaxSlider, clickerMinSlider;
private JTextField clickerMinField, clickerMaxField;
private JCheckBox clickInsideMinecraft, autoBlock;
public ClickOptionPanel() {
setLayout(new BorderLayout());
add(getClickerTitlePanel(), BorderLayout.NORTH);
add(getClickerSliderPanel(), BorderLayout.CENTER);
add(getCheckBoxPanel(), BorderLayout.SOUTH);
}
private JPanel getClickerTitlePanel() {
JPanel panel = new JPanel();
panel.setBorder(BorderFactory.createEtchedBorder());
clickerTitle = new JLabel("Clicker Options");
clickerTitle.setFont(font);
panel.add(clickerTitle);
return panel;
}
private JPanel getClickerSliderPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
clickerMaxSlider = new JSlider(0, 200, 125);
clickerMaxSlider.setPreferredSize(new Dimension(300, 45));
clickerMinSlider = new JSlider(0, 200, 75);
clickerMinSlider.setPreferredSize(new Dimension(300, 45));
panel.add(clickerMaxSlider, BorderLayout.NORTH);
panel.add(clickerMinSlider, BorderLayout.CENTER);
panel.add(getClickFieldPanel(), BorderLayout.SOUTH);
return panel;
}
private JPanel getClickFieldPanel() {
JPanel panel = new JPanel();
clickerMaxField = new JTextField(10);
clickerMaxField.setFont(font);
clickerMaxField.setHorizontalAlignment(SwingConstants.CENTER);
clickerMinField = new JTextField(10);
clickerMinField.setFont(font);
clickerMinField.setHorizontalAlignment(SwingConstants.CENTER);
panel.add(clickerMinField);
panel.add(clickerMaxField);
return panel;
}
private JPanel getCheckBoxPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBorder(BorderFactory.createEtchedBorder());
clickInsideMinecraft = new JCheckBox("Only click inside of Minecraft: ");
clickInsideMinecraft.setHorizontalTextPosition(SwingConstants.LEFT);
autoBlock = new JCheckBox("Enable auto-block: ");
autoBlock.setHorizontalTextPosition(SwingConstants.LEFT);
panel.add(clickInsideMinecraft, BorderLayout.NORTH);
panel.add(autoBlock, BorderLayout.SOUTH);
return panel;
}
There is the JPanel which I am sending. I create a new instance of it before it is sent.
The JPanel is turning up blank - why is this?
I was doing everything right - it was just that on the client side I forgot to set the ois.readObject object to the panel!

Java : Null Pointer Exception

I have to do a chat client/server project, but i am getting a Null Pointer Exception on pr1.println(msg) on the ChatServer1 class.
Any help would be appreciated.
public class ChatClient1 extends JFrame{
private JPanel contentPane;
private JPanel panel_1 = new JPanel();
private static JTextArea textArea = new JTextArea();
private static JTextField Txt1 = new JTextField();
private JButton DisconnectBtn = new JButton("DISCONNECT");
private static JButton SendTxt = new JButton("SEND");
private JLabel lbl1 = new JLabel("Message to send");
ServerSocket serversocket;
static BufferedReader br1;
static PrintWriter pr1;
Socket socket;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ChatServer1 frame = new ChatServer1();
frame.setVisible(true);
frame.setTitle("CLIENT");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ChatClient1() {
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 542, 383);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
panel_1.setBackground(Color.GRAY);
panel_1.setBounds(0, 0, 536, 355);
contentPane.add(panel_1);
panel_1.setLayout(null);
DisconnectBtn.setBounds(29, 220, 183, 33);
panel_1.add(DisconnectBtn);
textArea.setBounds(235, 11, 291, 242);
panel_1.add(textArea);
Txt1.setBounds(29, 303, 387, 41);
panel_1.add(Txt1);
Txt1.setColumns(10);
SendTxt.setBounds(437, 303, 89, 41);
panel_1.add(SendTxt);
lbl1.setBounds(29, 278, 123, 14);
panel_1.add(lbl1);
try {
Socket socket = new Socket("LocalHost" , 5000);
pr1 = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
br1 = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while(true){
textArea.append("Server: " + br1.readLine() + '\n' );
}
} catch (IOException e) {
}
SendTxt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String msg = Txt1.getText();
pr1.println(msg);
pr1.flush();
textArea.append(msg + '\n');
Txt1.setText("");
}
});
}
}
ChatServer1 class:
public class ChatServer1 extends JFrame{
private JPanel contentPane;
private JPanel panel_1 = new JPanel();
private static JTextArea textArea = new JTextArea();
private static JTextField Txt1 = new JTextField();
private JButton DisconnectBtn = new JButton("DISCONNECT");
private static JButton SendTxt = new JButton("SEND");
private JLabel lbl1 = new JLabel("Message to send");
static BufferedReader br1;
static PrintWriter pr1;
Socket socket;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ChatServer1 frame = new ChatServer1();
frame.setVisible(true);
frame.setTitle("SERVER");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ChatServer1() {
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 542, 383);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
panel_1.setBackground(Color.GRAY);
panel_1.setBounds(0, 0, 536, 355);
contentPane.add(panel_1);
panel_1.setLayout(null);
DisconnectBtn.setBounds(29, 220, 183, 33);
panel_1.add(DisconnectBtn);
textArea.setBounds(235, 11, 291, 242);
panel_1.add(textArea);
Txt1.setBounds(29, 303, 387, 41);
panel_1.add(Txt1);
Txt1.setColumns(10);
SendTxt.setBounds(437, 303, 89, 41);
panel_1.add(SendTxt);
lbl1.setBounds(29, 278, 123, 14);
panel_1.add(lbl1);
try {
ServerSocket serversocket = new ServerSocket(5000);
socket = serversocket.accept();
pr1 = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);
br1 = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while(true){
textArea.append("Client: " + br1.readLine() + '\n' );
}
} catch (IOException e) {
}
SendTxt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String msg = Txt1.getText();
pr1.println(msg);
pr1.flush();
textArea.append(msg + '\n');
Txt1.setText("");
}
});
}
}
your problem is with the ChatServer1 code, here you have the following:
ServerSocket serversocket = new ServerSocket(5000);
socket = serversocket.accept();
When you call accept, its waiting and listening for an incoming connection so never actually reaches your instantiation of pr1. Hence pr1 stays as null. Easy to fix simply move the pr1 instantiation above the accept call like this:
pr1 = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()),true);
ServerSocket serversocket = new ServerSocket(5000);
socket = serversocket.accept();
Hope this helps!

Adding numbers to an arraylist from the Jtextfield

I am sure its very simple but this is my first java class. the user enters a number into the input Jtextfield. the Add button is supposed to add that number to the arraylist. I am having trouble figuring out how to do that exactly. Any help you can give me would be awesome
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class ArrayExercise extends JFrame
{
private final int WINDOW_WIDTH = 300;
private final int WINDOW_HEIGHT = 300;
private JPanel panel1;
private JPanel panel2;
private JLabel messageLabel;
private JTextField input;
private JTextArea output;
private JButton addButton;
private JButton list;
private JButton rlist;
private JButton clear;
public ArrayExercise()
{
setTitle("Array Exercise");
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
panel1();
panel2();
add(panel1, BorderLayout.EAST);
add(panel2, BorderLayout.WEST);
setVisible(true);
input.requestFocus();
}
private void panel1()
{
messageLabel = new JLabel("Input");
input = new JTextField(5);
addButton = new JButton("Add");
list = new JButton("List");
rlist = new JButton("R-List");
clear = new JButton("Clear");
addButton.addActionListener(new ButtonListener());
list.addActionListener(new ButtonListener());
rlist.addActionListener(new ButtonListener());
clear.addActionListener(new ButtonListener());
panel1 = new JPanel();
panel1.setLayout(new GridLayout(6,1));
panel1.add(messageLabel);
panel1.add(input);
panel1.add(addButton);
panel1.add(list);
panel1.add(rlist);
panel1.add(clear);
}
private void panel2()
{
output = new JTextArea(12, 10);
panel2 = new JPanel();
panel2.add(output);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String in;
int number;
int index = 0;
ArrayList<String> list = new ArrayList<>();
String actionCommand = e.getActionCommand();
if (actionCommand.equals("Add"))
{
index++;
in = addButton.getText();
list.add(addButton.getText());
if (index == 9)
{
input.setEditable(false);
addButton.setEnabled(false);
}
output.setText(in + " added.");
input.setText(null);
input.requestFocus();
}
if (actionCommand.equals("List"))
{
for(int x = 0; x <= list.size(); x++)
{
output.setText((x+1)+ ". " + list.get(x) + "\n");
}
}
}
}
public static void main(String[] args)
{
new ArrayExercise();
}
}
You have ArrayList list which is not adding any string value to that list and you are trying to run that over loop to get you values. If you are not adding anything to list then how can you extract anything out of it.
ArrayList<String> list = new ArrayList<String>();
For each button attach different actionlistener as all buttons are not supposed to act same way.
To add elements in ArrayList use this
list.add(input.getText()); // adding text entered into input textfield.
Make a list
List item
Make a TextField
Make Button Add Listener to button
Get the text from the text field or text area Add to array list
object
Here is all the work you need to do:
ArrayList<String> arrayObject= new ArrayList<String>();
JButton button = new JButton();
JtextField textBox = new JtextField ();
button.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
//inside your action listener:
String add_item_to_array = textBox.getText().trim();
arrayObject.add(add_item_to_array);
}
});