mport java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.*;
public class Topo extends JFrame {
public static void main(String[] args) {
Topo topo=new Topo();
System.out.println("main()结束");
}
final String userName2 = "";
final String passwrod1 = "123";
final String passwrod2 = "123";
JFrame jFrame = new JFrame("登陆界面");
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
jFrame.setBounds(((int)dimension.getWidth() - 400) / 2, ((int)dimension.getHeight() - 300) / 2, 400,250);
jFrame.setResizable(false);//禁止窗体改变大小
jFrame.setLayout(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel titleLabel = new JLabel("登陆界面");
titleLabel.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,17));//设置标签字体
titleLabel.setBounds(140, 0,150 ,60 );
jFrame.add(titleLabel);
JLabel label1 = new JLabel("姓名");
label1.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,17));//设置标签字体
label1.setBounds(140, 55, 50,20);
jFrame.add(label1);
JLabel label2 = new JLabel("密码");
label2.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,17));//设置标签字体
label2.setBounds(140, 95, 50, 20);
jFrame.add(label2);
final JTextField text1 = new JTextField();
text1.setBounds(180, 50, 150, 30);
jFrame.add(text1);
final JPasswordField text2 = new JPasswordField();
text2.setBounds(180, 90, 150, 30);
jFrame.add(text2);
ButtonGroup buttonGroup = new ButtonGroup(); //单选按钮组
final JRadioButton radioButtonA = new JRadioButton("客户端", true);
radioButtonA.setBounds(50,145,80,20);
buttonGroup.add( radioButtonA);
jFrame.add(radioButtonA);
final JRadioButton radioButtonB = new JRadioButton("管理员端", false);
radioButtonB.setBounds(50,165,80,20);
buttonGroup.add( radioButtonB);
jFrame.add(radioButtonB);
JButton button = new JButton("登陆");
button.setBounds(250, 150, 60, 30);
jFrame.add(button);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(radioButtonA.isSelected() && userName1.equals(text1.getText()) && passwrod1.equals(text2.getText()))
{
fram();//调用客户端方法frame();
JOptionPane.showMessageDialog(null, "欢迎使用客户端", "提示", JOptionPane.INFORMATION_MESSAGE);
}
else if(radioButtonB.isSelected() && userName2.equals(text1.getText()) && passwrod1.equals(text2.getText()))
{
gly();//调用客户端方法frame();
JOptionPane.showMessageDialog(null, "欢迎使用管理员端", "提示", JOptionPane.INFORMATION_MESSAGE);
}
else {
JOptionPane.showMessageDialog(null, "用户名或密码错误,请核对后重新输入", "提示", JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
}
});
jFrame.add(button);
jFrame.setVisible(true);
}
public void fram()
{
TextArea area=new TextArea(10,40);
JLabel label=new JLabel("图");
JFrame f=new JFrame("客户端"); //框架
area.setFont(new Font("TimesRoman",Font.PLAIN, 28));
JButton button = new JButton("欢迎使用");
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
panel1.setLayout(new BorderLayout());
panel1.add(button);
panel2.add(label);
f.add(area);
f.add(panel1,"South");
f.add(panel2,"North");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//f.setLocation(300,50);//设置窗体弹出的坐标
f.setSize(1010,700);
f.setVisible(true);
}
public void gly(){
JFrame f; //定义各种构件
JButton button;
JLabel label=new JLabel("管理员端");
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
f=new JFrame("图"); //框架
panel1.setLayout(new BorderLayout());
panel2.add(label);
f.add(panel1,"South");
f.add(panel2,"North");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(1010,700);
f.setVisible(true);
}
}
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import java.awt.*;
public class Topo extends JFrame {
public static void main(String[] args) {
Topo topo=new Topo();
System.out.println("main()结束");
}
public Topo(){
System.out.println("进入Topo");
final String userName1 = "abc";final String userName2 = "";
final String passwrod1 = "123";
final String passwrod2 = "123";
JFrame jFrame = new JFrame("登陆界面");
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
jFrame.setBounds(((int)dimension.getWidth() - 400) / 2, ((int)dimension.getHeight() - 300) / 2, 400,250);
jFrame.setResizable(false);//禁止窗体改变大小
jFrame.setLayout(null);
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel titleLabel = new JLabel("登陆界面");
titleLabel.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,17));//设置标签字体
titleLabel.setBounds(140, 0,150 ,60 );
jFrame.add(titleLabel);
JLabel label1 = new JLabel("姓名");
label1.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,17));//设置标签字体
label1.setBounds(140, 55, 50,20);
jFrame.add(label1);
JLabel label2 = new JLabel("密码");
label2.setFont(new Font("宋体",Font.BOLD | Font.ITALIC,17));//设置标签字体
label2.setBounds(140, 95, 50, 20);
jFrame.add(label2);
final JTextField text1 = new JTextField();
text1.setBounds(180, 50, 150, 30);
jFrame.add(text1);
final JPasswordField text2 = new JPasswordField();
text2.setBounds(180, 90, 150, 30);
jFrame.add(text2);
ButtonGroup buttonGroup = new ButtonGroup(); //单选按钮组
final JRadioButton radioButtonA = new JRadioButton("客户端", true);
radioButtonA.setBounds(50,145,80,20);
buttonGroup.add( radioButtonA);
jFrame.add(radioButtonA);
final JRadioButton radioButtonB = new JRadioButton("管理员端", false);
radioButtonB.setBounds(50,165,80,20);
buttonGroup.add( radioButtonB);
jFrame.add(radioButtonB);
JButton button = new JButton("登陆");
button.setBounds(250, 150, 60, 30);
jFrame.add(button);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(radioButtonA.isSelected() && userName1.equals(text1.getText()) && passwrod1.equals(text2.getText()))
{
fram();//调用客户端方法frame();
JOptionPane.showMessageDialog(null, "欢迎使用客户端", "提示", JOptionPane.INFORMATION_MESSAGE);
}
else if(radioButtonB.isSelected() && userName2.equals(text1.getText()) && passwrod1.equals(text2.getText()))
{
gly();//调用客户端方法frame();
JOptionPane.showMessageDialog(null, "欢迎使用管理员端", "提示", JOptionPane.INFORMATION_MESSAGE);
}
else {
JOptionPane.showMessageDialog(null, "用户名或密码错误,请核对后重新输入", "提示", JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
}
});
jFrame.add(button);
jFrame.setVisible(true);
}
public void fram()
{
TextArea area=new TextArea(10,40);
JLabel label=new JLabel("图");
JFrame f=new JFrame("客户端"); //框架
area.setFont(new Font("TimesRoman",Font.PLAIN, 28));
JButton button = new JButton("欢迎使用");
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
panel1.setLayout(new BorderLayout());
panel1.add(button);
panel2.add(label);
f.add(area);
f.add(panel1,"South");
f.add(panel2,"North");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//f.setLocation(300,50);//设置窗体弹出的坐标
f.setSize(1010,700);
f.setVisible(true);
}
public void gly(){
JFrame f; //定义各种构件
JButton button;
JLabel label=new JLabel("管理员端");
JPanel panel1=new JPanel();
JPanel panel2=new JPanel();
f=new JFrame("图"); //框架
panel1.setLayout(new BorderLayout());
panel2.add(label);
f.add(panel1,"South");
f.add(panel2,"North");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(1010,700);
f.setVisible(true);
}
}
PS:新手上路。