📄 testlr.java
字号:
package com.oristand;
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Date;
import javax.swing.*;
import javax.swing.event.AncestorListener;
public class TestLR {
JFrame jf1=new JFrame("主界面");
JPanel jp1=new JPanel();
JPanel jp12=new JPanel();
JLabel jl11=new JLabel("用户名");
JLabel jl12=new JLabel("密码");
JTextField jtf11=new JTextField(10);
TextField tf12=new TextField(10);
JButton jb11=new JButton("注册");
JButton jb12=new JButton("登陆");
JButton jb14=new JButton("时间");
JDialog jd1=new JDialog(jf1,"错误信息",true);
JButton jb13=new JButton("用户名或密码错误");
JFrame jf2=new JFrame("注册界面");
JPanel jp2=new JPanel();
JPanel jp22=new JPanel();
JLabel jl21=new JLabel("用户名");
JLabel jl22=new JLabel("密码");
JLabel jl23=new JLabel("确认密码");
JTextField jtf21=new JTextField(15);
TextField tf22=new TextField(15);
TextField tf23=new TextField(15);
JButton jb21=new JButton("注册");
JButton jb22=new JButton("重置");
JDialog jd21=new JDialog(jf2,"错误信息",true);
JDialog jd22=new JDialog(jf2,"ok",true);
JDialog jd23=new JDialog(jf2,"错误信息",true);
JDialog jd24=new JDialog(jf2,"错误信息",true);
JButton jb23=new JButton("请输入注册信息");
JButton jb24=new JButton("注册成功");
JButton jb25=new JButton("用户名已经存在");
JButton jb26=new JButton("两次密码不相同");
JFrame jf3=new JFrame("欢迎使用~~");
MyPanel jp3=new MyPanel();
JTextField jtf31=new JTextField(20);
JButton jb31=new JButton("退出");
JLabel jl31=new JLabel("黯灭");
JFrame jf4=new JFrame("电子时钟");
boolean flag=true;
JLabel jl41=new JLabel();
JPanel jp41=new JPanel();
Thread t = new MyClockThread();
JButton jb41 = new JButton("stop");
JButton jb42 = new JButton("start");
int i = 0;
public TestLR(){
jf1.setSize(200,200);
jf1.setLocation(450, 250);
jf1.add(jp1,BorderLayout.CENTER);
jf1.add(jp12,BorderLayout.SOUTH);
jp1.setLayout(new GridLayout(2,2,5,10));
jp1.add(jl11);
jp1.add(jtf11);
jp1.add(jl12);
jp1.add(tf12);
jp12.setLayout(new GridLayout(1,3,5,5));
jp12.add(jb11);
jp12.add(jb12);
jp12.add(jb14);
jd1.setSize(100,100);
jd1.setLayout(new BorderLayout());
jd1.add(jb13, BorderLayout.CENTER);
tf12.setEchoChar('*');
jf1.setVisible(true);
jf1.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//Thread t1=new MyClockThread1();
//t1.start();
jf2.setSize(200,200);
jf2.setLocation(450, 250);
jf2.add(jp2,BorderLayout.CENTER);
jf2.add(jp22,BorderLayout.SOUTH);
jp2.setLayout(new GridLayout(3, 2, 5, 10));
jp2.add(jl21);
jp2.add(jtf21);
jp2.add(jl22);
jp2.add(tf22);
jp2.add(jl23);
jp2.add(tf23);
jp22.setLayout(new GridLayout(1, 2, 5, 5));
jp22.add(jb21);
jp22.add(jb22);
jd21.add(jb23);
jd21.setSize(100,100);
jd22.add(jb24);
jd22.setSize(100,100);
jd23.add(jb25);
jd23.setSize(100,100);
jd24.add(jb26);
jd24.setSize(100,100);
tf22.setEchoChar('*');
tf23.setEchoChar('*');
jf3.setSize(300,300);
jf3.add(jb31,BorderLayout.SOUTH);
jf3.add(jp3,BorderLayout.CENTER);
jf3.add(jtf31,BorderLayout.NORTH);
jf3.add(jl31,BorderLayout.WEST);
jf4.setSize(200,200);
jf4.add(jl41,BorderLayout.NORTH);
jf4.add(jp41,BorderLayout.CENTER);
jp41.setBackground(Color.blue);
jp41.add(jb41);
jp41.add(jb42);
jb11.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jf2.setVisible(true);
}});
jb12.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String s1 = jtf11.getText();
String s2 = tf12.getText();
if (Login.Login(s1, s2)) {
Client c=new Client();
} else {
jd1.setVisible(true);
}
}
});
jb13.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd1.setVisible(false);
}
});
jb14.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jf4.setVisible(true);
Thread t=new MyClockThread();
t.start();
}
});
jb21.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String filename ="c:\\jilu.txt";
String s1=jtf21.getText();
String s2=tf22.getText();
String s3=tf23.getText();
String s=s1+","+s2;
if (s1.equals("") || s2.equals("")) {
jd21.setVisible(true);
}
else if(s1!=""&& s2!=" "){
if(Register.exist(filename, s1)){
jd23.setVisible(true);
}
else{
Register.saveInformation(filename, s);
jd22.setVisible(true);
}}
if(!s2.equals(s3)){
jd24.setVisible(true);
}
}
});
jb22.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
jtf21.setText(null);
tf22.setText(null);
tf23.setText(null);
}
});
jb23.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd21.setVisible(false);
}
});
jb24.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd22.setVisible(false);
}
});
jb25.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd23.setVisible(false);
}
});
jb26.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
jd24.setVisible(false);
}
});
jb31.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO 自动生成方法存根
jf3.setVisible(false);
}
});
jb41.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
flag = false;
}
});
jb42.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
t = new MyClockThread();
flag = true;
t.start();
}
});
}
public class MyMouseAdapter extends MouseAdapter{
public void mouseEntered(MouseEvent e){
jp3.setBackground(Color.blue);
}
public void mouseExited(MouseEvent e){
jp3.setBackground(Color.red);
}
}
class MyClockThread1 extends Thread{
public void run(){
try {
while(true){
jp1.setBackground(new Color(i%255,i%255,100));
Thread.sleep(100);
i+=10;
}
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
class MyClockThread extends Thread{
public void run(){
try {
while(flag){
jp41.setBackground(new Color(i%255,i%255,100));
jl41.setText(new Date().toString());
Thread.sleep(500);
i += 10;
}
} catch (InterruptedException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
TestLR tl=new TestLR();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -