I'm trying to make a program using java and swing gui. I want a total of 3 windows/JFrames to be used. The first window opens well and I have added 2 buttons in the first window. After clicking on those buttons I want 2 other windows to open.
The program itself is to perform matrix operations and scientific calculations. The first window has two buttons clicking on which the desired operation is to be performed.
I have cleated 3 java files in total, one java file has the Swing gui elements to display the two buttons. And other 2 java files which perform the matrix calculations and scientific calculations
I want to open the two other java classes when a button is clicked. I searched online for articles to follow but none of it worked. So, please help me out. Code of the main java file is given below.
class calculator
{
public static void main(String args[])
{
JFrame f = new JFrame("2 in 1 Calculator");
JButton b=new JButton("Matrix");
b.setBounds(50,100,95,30);
f.add(b);
f.setLayout(null);
f.setVisible(true);
b.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
MatrixPanel m1=new MatrixPanel();
m1.setVisible(true);
}
});
JButton b1=new JButton("Scientific");
b1.setBounds(200,100,95,30);
f.add(b1);
f.setLayout(null);
f.setVisible(true);
b1.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e) {
ScientificPanel p1=new ScientificPanel();
p1.setVisible(true);
}
});
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(420,420);
}
}
The name of the other two java files is ScientificCalculator.java and MatrixCalculator.java. I am ready to provide more information pertaining to the code as well. Help is really appreciated