I was trying to create a simple JFrame input and output GUI with an ActionListener which will listen for 3 buttons (Submit, Clear All, and Okay) and I separated their function and contained them in their respective class (btnSubmit, btnClearAll, btnOkay). Now the problem is that as you have already read on the title, the output JFrame (OutFrame) won't show its components. OutFrame not showing My code goes like this:
package eventdriven_dineros;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EventDriven_Dineros extends JFrame implements ActionListener{
JFrame InFrame = new JFrame("INPUT");
JFrame OutFrame = new JFrame("OUTPUT");
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
FlowLayout fl = new FlowLayout();
JLabel lb1 = new JLabel("First Name: ");
JLabel lb2 = new JLabel("Last Name: ");
JLabel lb3 = new JLabel("Middle Name: ");
JLabel lb4 = new JLabel("Mobile Number:");
JLabel lb5 = new JLabel("E-mail Address: ");
JLabel lb6 = new JLabel(" ");
JLabel lb7 = new JLabel(" ");
JLabel lb8 = new JLabel(" ");
JLabel lb9 = new JLabel(" ");
JLabel lb10 = new JLabel(" ");
JTextField tf1 = new JTextField(15);
JTextField tf2 = new JTextField(15);
JTextField tf3 = new JTextField(15);
JTextField tf4 = new JTextField(15);
JTextField tf5 = new JTextField(15);
JButton btnSub = new JButton("Submit");
JButton btnClear = new JButton("Clear All");
JButton btnOk = new JButton("Okay");
public EventDriven_Dineros(){
InFrame.setSize(230,380);
panel1.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 10));
panel1.setBackground(Color.yellow);
panel1.add(lb1);
panel1.add(tf1);
panel1.add(lb2);
panel1.add(tf2);
panel1.add(lb3);
panel1.add(tf3);
panel1.add(lb4);
panel1.add(tf4);
panel1.add(lb5);
panel1.add(tf5);
panel1.add(btnSub);
panel1.add(btnClear);
InFrame.add(panel1);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
InFrame.setVisible(true);
ActionListener subListen = new btnSubmit();
ActionListener clearListen = new btnClearAll();
btnSub.addActionListener(subListen);
btnClear.addActionListener(clearListen);
}
public void outFrame(){
OutFrame.setSize(500,300);
panel2.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 10));
panel2.add(lb1);
panel2.add(lb2);
panel2.add(lb3);
panel2.add(lb4);
panel2.add(lb5);
panel2.add(btnOk);
OutFrame.add(panel2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ActionListener okListen = new btnOkay();
btnOk.addActionListener(okListen);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnSub){
new btnSubmit();
}
if (e.getSource() == btnClear){
new btnClearAll();
}
if (e.getSource() == btnOk){
new btnOkay();
}
}
class btnSubmit implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
OutFrame.setVisible(true);
String name1 = tf1.getText();
String name2 = tf2.getText();
String name3 = tf3.getText();
String name4 = tf4.getText();
String name5 = tf5.getText();
lb6.setText("First Name: " + name1);
lb7.setText("Last Name: " + name2);
lb8.setText("Middle Name: " + name3);
lb9.setText("Mobile Number: " + name4);
lb10.setText("E-mail Address: " + name5);
btnSub.setEnabled(false);
}
}
class btnClearAll implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
OutFrame.setVisible(false);
}
}
class btnOkay implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
OutFrame.dispose();
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
}
public static void main(String[] args) {
new EventDriven_Dineros();
}
}
I haven't tried anything yet because I don't know where to start.