一个简单的登陆界面程序
2013-10-05 21:00
351 查看
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()结束");
}
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:新手上路。
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:新手上路。
相关文章推荐
- 用Html写一个简单的登陆界面
- 一个简单WPF登陆界面,包含记住密码,自动登录等功能,简洁美观
- java学习笔记之使用MyEclipse写一个简单的登陆界面(二)
- struts2入门-第一个例子==》第一个struts2实例——HelloWorld==》Struts2.0搭建和简单实例==>写一个Steuts2的经典入门案例,做了一个登陆程序作为入门例子
- 一个简单的工资管理程序(大二,无界面)
- C/C++做的一个简单界面程序扩充,向指定窗口发送消息源代码
- Android学习笔记:创建一个简单的双界面程序
- 用Html写一个简单的登陆界面
- 一个简单的登陆界面
- 一个简单大气的登陆(login)界面源码介绍学习
- DuiVision开发教程(2)-如何写一个简单的界面程序
- C#编写的一个简单的登陆界面对话框的原代码
- 一个有意思的笔试题:如何破解一个简单密码登陆程序
- 一个简单的安卓仿qq登陆界面
- 基于vs2008的一个简单的多线程聊天程序(有界面)
- 一个简单的matlab图形界面程序GUI
- Android如何制作一个简单的登陆界面
- C/C++做的一个简单界面程序
- 用python写一个简单的用户登陆程序(要求写成函数)
- 用Java写的一个类似QQ登陆界面的程序 Java QQ登陆界面