I have two JFrames
newAccessLevels.java, which has two buttons "Level 1" "Level 2" and newAccessPanel.java
I need to get the level that the user selects "1 or 2" onto the accessPanel
so I can display it in the title of the accessPanel.java e.g. Access Level 1, Access Level 2. How can this be done. below is example code, so if level 1 is clicked the newAccessPanel JFrame will open with the title *ACCESS LEVEL 1 and vice versa for level 2:
newAccessLevels.java
package securitySystem;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class newAccessLevels extends JFrame{
public static void main (String args[]){
newAccessLevels gui= new newAccessLevels ();
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setTitle("Access Levels");
gui.setSize(400,400);
gui.setLocationRelativeTo(null);
gui.setVisible(true);
}
JButton btnLevel1= new JButton("Levels 1");
JButton btnLevel2= new JButton("Level 2");
public newAccessLevels (){
setLayout (null);
btnLevel1.setBounds(120,70, 150, 30);
add(btnLevel1);
btnLevel2.setBounds(120,130, 150, 30);
add(btnLevel2);
}
public void calcButtons()
{
btnLevel1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
newAccessPanel gui =new newAccessPanel();
gui.setSize (360, 450);
gui.setLocationRelativeTo(null);
gui.setVisible(true);
dispose();
}
});
btnLevel2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
newAccessPanel gui =new newAccessPanel();
gui.setSize (360, 450);
gui.setLocationRelativeTo(null);
gui.setVisible(true);
dispose();
}
});
}
}
newAccessPanel.java
package securitySystem;
import java.awt.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.*;
public class newAccessPanel extends JFrame{
public static void main (String args[]){
newAccessPanel gui= new newAccessPanel ();
gui.setSize (360, 450);
gui.setLocationRelativeTo(null);
gui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gui.setVisible(true);
gui.setTitle("ACCESS LEVEL '1/2'");
//gui.setLayout(new BorderLayout());
//gui.setBackground(Color.BLACK);
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…