我是一名JAVA新手,接触JAVA不足一月,从学JAVA的那天起我就编这个程序,直到现在,我还在改这个程序,还有4个月的课程,我希望这个程序能够一直陪伴我走完这后面的4个月,为了巩固所学知识,我想把我所学知识全部融入进去,恳请各位给个意见个建议,帮忙扩充增加新知识!特此感谢!
import javax.swing.border.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
class chuanqi2
{
Vector v1;
String name1;
String passwd;
String repasswd;
String sex;
String youxiang;
public chuanqi2()
{
}
public chuanqi2(String name1,String passwd,String repasswd,String sex,String youxiang)
{
this.name1=name1;
this.passwd=passwd;
this.repasswd=repasswd;
this.sex=sex;
this.youxiang=youxiang;
}
}
public class chuanqi extends WindowAdapter implements ActionListener
{
JFrame f1,f2,f3,f4,f5;
JPanel p11,p12,p13,p21,p22,p23,p31,p32,p41,p42,p43,p51;
Container contentPane1,contentPane2,contentPane3,contentPane4,contentPane5;
JLabel lab11,lab12,Lab12,lab13,lab14,lab15,lab21,lab31,lab32,lab33,lab41,lab42,lab43;
JTextField tf11,tf12,Tf12,tf13,tf14,tf31,tf32,tf41,tf42;
JButton btn11,btn12,btn13,btn21,btn22,btn31,btn32,btn41,btn42;
//JPasswordField tf42;
Choice chc;
JCheckBox c21,c22,c23,c24;
JMenuBar mb51;
JMenu m51,m52,m53,m54,m55,m56,m57;
JMenuItem mi511,mi512,mi513,mi514,mi521,mi522,mi523,mi524,mi531,mi532,mi533,mi534,mi535,mi536,mi541,mi554,
mi555,mi561;
JCheckBoxMenuItem mi551,mi552,mi553;
ButtonGroup bgroup2,bgroup5;
Vector v1=new Vector();
public chuanqi()
{
f1 = new JFrame("欢迎登陆热血传奇1");
contentPane1 = f1.getContentPane();
contentPane1.setLayout(new BorderLayout());
//f1.setBackground(Color.pink);
p11 = new JPanel();
p11.setLayout(new GridLayout(5,2));
//p1.setBorder(Borderfactory.createTitledBorder("请填写注册信息"));
p12 = new JPanel();
p13 = new JPanel();
lab11 = new JLabel("帐 号:");
lab12 = new JLabel("密 码:");
Lab12 = new JLabel("确认密码:");
lab13 = new JLabel("性 别:");
lab14 = new JLabel("电子邮箱:(可选)");
tf11 = new JTextField();
tf12 = new JPasswordField();
Tf12 = new JPasswordField();
tf13 = new JTextField();
tf14 = new JTextField();
p11.add(lab11);
p11.add(tf11);
tf11.addActionListener(this);
p11.add(lab12);
p11.add(tf12);
tf12.addActionListener(this);
p11.add(Lab12);
p11.add(Tf12);
Tf12.addActionListener(this);
p11.add(lab13);
p11.add(tf13);
p11.add(lab14);
p11.add(tf14);
chc = new Choice();
chc.add("男");
chc.add("女");
tf13.add(chc);
lab15 = new JLabel("请填写注册信息");
p12.add(lab15);
contentPane1.add(p11,BorderLayout.CENTER);
contentPane1.add(p12,BorderLayout.NORTH);
contentPane1.add(p13,BorderLayout.SOUTH);
btn11 = new JButton("NEXT");
btn11.addActionListener(this);
btn12 = new JButton("CANCEL");
btn12.addActionListener(this);
btn13 = new JButton("EXIT");
btn13.addActionListener(this);
p13.add(btn11);
p13.add(btn12);
p13.add(btn13);
f1.setSize(300,220);
//v1=new Vector();
//f.pack();
f1.setResizable(false);
f1.setVisible(true);
//f1.show();
p11.setBackground(Color.pink);
p12.setBackground(Color.pink);
p13.setBackground(Color.pink);
btn11.setBackground(Color.red);
btn12.setBackground(Color.red);
btn13.setBackground(Color.red);
f1.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
}
public void actionPerformed(ActionEvent e)
{
Object obj = e.getSource();
chuanqi2 cq=new chuanqi2();
if((e.getActionCommand()).equals("EXIT"))
{
Toolkit.getDefaultToolkit().beep();
f1.dispose();
}
else
if((e.getActionCommand()).equals("CANCEL"))
{
tf11.setText("");
tf12.setText("");
Tf12.setText("");
tf13.setText("");
tf14.setText("");
}
if((e.getActionCommand()).equals("NEXT"))
{
if(!tf12.getText().equals(Tf12.getText()))
{
JOptionPane.showMessageDialog(null,"密码和确认密码不同,请重新输入!");
}
else
if(tf11.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"帐号不能为空!");
}
else
if(tf12.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"密码不能为空!");
}
else
{
cq=new chuanqi2(tf11.getText(),tf12.getText(),Tf12.getText(),tf13.getText(),tf14.getText());
v1.addElement(cq);
cq=(chuanqi2)v1.elementAt(0);
if(v1.contains(cq))
{
//cq=(chuanqi2)v1.elementAt(0);
if(cq.name1.equals(tf11.getText()))
{
JOptionPane.showMessageDialog(null,"帐号已存在!"+cq.name1);
}
else
{
v1.addElement(cq);
JOptionPane.showMessageDialog(null,"bucuizai");
}
}
f2 = new JFrame("欢迎登陆热血传奇2");
contentPane2 = f2.getContentPane();
p21 = new JPanel();
p22 = new JPanel();
p23 = new JPanel();
//contentPane2.setLayout(new BorderLayout());
contentPane2.add(p21,BorderLayout.CENTER);
f2.setSize(500,350);
f2.setLocation(200,200);
lab21 = new JLabel("请选择要创建的角色");
p21.add(lab21);
c21 = new JCheckBox("战士");
//c41.setBorderPaintedFlat(boolean b)
p22.add(c21);
c22 = new JCheckBox("法师");
p22.add(c22);
c23 = new JCheckBox("道士");
p22.add(c23);
c24 = new JCheckBox("矿工");
p22.add(c24);
bgroup2 = new ButtonGroup();
bgroup2.add(c21);
bgroup2.add(c22);
bgroup2.add(c23);
bgroup2.add(c24);
p22.setLayout(new GridLayout(4,1));
btn21 = new JButton("提交");
btn21.addActionListener(this);
p23.add(btn21);
btn22 = new JButton("退出");
btn22.addActionListener(this);
p23.add(btn22);
contentPane2.add(p21,BorderLayout.NORTH);
contentPane2.add(p22,BorderLayout.CENTER);
contentPane2.add(p23,BorderLayout.SOUTH);
f2.show();
f2.setResizable(false);
f1.dispose();
}
}
if((e.getActionCommand()).equals("退出"))
{
Toolkit.getDefaultToolkit().beep();
f2.dispose();
}
if((e.getActionCommand()).equals("提交"))
{
f3 = new JFrame("欢迎登陆热血传奇3");
contentPane3 = f3.getContentPane();
f3.setSize(300,200);
f3.setLocation(300,300);
contentPane3.setLayout(new BorderLayout());
p31 = new JPanel();
lab31 = new JLabel("注册成功");
p31.add(lab31);
contentPane3.add(p31,BorderLayout.CENTER);
p32 = new JPanel();
btn31 = new JButton("下一步");
btn31.addActionListener(this);
p32.add(btn31);
contentPane3.add(p32,BorderLayout.SOUTH);
//newf.setBackground(Color.pink);
f3.setResizable(false);
f3.show();
f2.dispose();
}
if((e.getActionCommand()).equals("下一步"))
{
f4 = new JFrame("欢迎登陆热血传奇4");
contentPane4 = f4.getContentPane();
p41 = new JPanel();
p42 = new JPanel();
p43 = new JPanel();
contentPane4.setLayout(new BorderLayout());
p42.setLayout(new GridLayout(2,2));
f4.setSize(200,150);
f4.setLocation(100,100);
lab41 = new JLabel("请输入登陆信息");
lab42 = new JLabel("帐 号:");
lab43 = new JLabel("密 码:");
tf41 = new JTextField();
tf42 = new JPasswordField();
btn41 = new JButton("确认");
btn41.addActionListener(this);
btn42 = new JButton("取消");
btn42.addActionListener(this);
p41.add(lab41);
p42.add(lab42);
p42.add(tf41);
p42.add(lab43);
p42.add(tf42);
p43.add(btn41);
p43.add(btn42);
contentPane4.add(p41,BorderLayout.NORTH);
contentPane4.add(p42,BorderLayout.CENTER);
contentPane4.add(p43,BorderLayout.SOUTH);
f4.setResizable(false);
f4.show();
f3.dispose();
}
if((e.getActionCommand()).equals("取消"))
{
Toolkit.getDefaultToolkit().beep();
f4.dispose();
}
if((e.getActionCommand()).equals("确认"))
{
if(tf41.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"帐号不能为空!");
}
else
{
if(tf41.getText().equals("chuanqi")&&(tf42.getText().equals("chuanqi")))
{
f5 = new JFrame("欢迎登陆热血传奇脱机外挂WL520测试版5.0");
contentPane5 = f5.getContentPane();
p51 = new JPanel();
contentPane5.setLayout(new BorderLayout());
contentPane5.add(p51,BorderLayout.WEST);
mb51 = new JMenuBar();
mb51.setLayout(new FlowLayout());
p51.add(mb51);
m51 = new JMenu("网络(N)");
m51.setMnemonic('N');
mb51.add(m51);
mi511 = new JMenuItem("登陆(L)");
mi511.setMnemonic('L');
m51.add(mi511);
mi512 = new JMenuItem("断开(O)");
mi512.setMnemonic('O');
m51.add(mi512);
mi513 = new JMenuItem("小退(B)");
mi513.setMnemonic('B');
m51.add(mi513);
m51.addSeparator();
mi514 = new JMenuItem("退出(X)");
mi514.setMnemonic('X');
mi514.addActionListener(this);
m51.add(mi514);
m52 = new JMenu("设置(S)");
m52.setMnemonic('S');
mb51.add(m52);
mi521 = new JMenuItem("代理服务器设置(P)");
mi521.setMnemonic('P');
m52.add(mi521);
mi522 = new JMenuItem("程序锁定(L)");
mi522.setMnemonic('L');
m52.add(mi522);
mi523 = new JMenuItem("系统设置(R)");
mi523.setMnemonic('R');
m52.addSeparator();
m52.add(mi523);
mi524 = new JMenuItem("WL520冲值(A)");
mi524.setMnemonic('A');
mi524.addActionListener(this);
m52.add(mi524);
m53 = new JMenu("查看(V)");
m53.setMnemonic('V');
mb51.add(m53);
mi531 = new JCheckBoxMenuItem("工具栏(T)");
mi531.setMnemonic('T');
m53.add(mi531);
mi532 = new JCheckBoxMenuItem("状态栏(S)");
mi532.setMnemonic('S');
m53.add(mi532);
m53.addSeparator();
mi533 = new JCheckBoxMenuItem("角色栏(C)");
mi533.setMnemonic('C');
m53.add(mi533);
mi534 = new JCheckBoxMenuItem("聊天栏(L)");
mi534.setMnemonic('L');
m53.add(mi534);
m53.addSeparator();
mi535 = new JMenuItem("显示地图(M)");
mi535.setMnemonic('M');
m53.add(mi535);
mi536 = new JMenuItem("战斗统计(R)");
mi536.setMnemonic('R');
mi536.addActionListener(this);
m53.add(mi536);
m54 = new JMenu("战斗(A)");
m54.setMnemonic('A');
mb51.add(m54);
mi541 = new JMenuItem("开始战斗(B)");
mi541.setMnemonic('B');
m54.add(mi541);
m55 = new JMenu("攻击模式(M)");
m55.setMnemonic('M');
mb51.add(m55);
mi551 = new JCheckBoxMenuItem("全体攻击模式");
m55.add(mi551);
mi552 = new JCheckBoxMenuItem("和平攻击模式");
m55.add(mi552);
mi553 = new JCheckBoxMenuItem("编组攻击模式");
m55.add(mi553);
mi554 = new JCheckBoxMenuItem("行会攻击模式");
m55.add(mi554);
mi555 = new JCheckBoxMenuItem("善恶对攻模式");
m55.add(mi555);
bgroup5 = new ButtonGroup();
bgroup5.add(mi551);
bgroup5.add(mi552);
bgroup5.add(mi553);
bgroup5.add(mi554);
bgroup5.add(mi555);
m56 = new JMenu("帮助(H)");
m56.setMnemonic('H');
mb51.add(m56);
mi561 = new JMenuItem("关于WL520外辅(A)");
mi561.setMnemonic('A');
m56.add(mi561);
m57 = new JMenu("打开记事本(O)");
m57.setMnemonic('O');
m57.addActionListener(this);
mb51.add(m57);
f5.setSize(600,400);
f5.setVisible(true);
f5.show();
f4.dispose();
}
else
{
JOptionPane.showMessageDialog(null,"密码错误");
}
}
}
if(obj == mi514)
{
int i=JOptionPane.showConfirmDialog(null,"你确定要退出吗!","你确定要退出吗?",
JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
if(i==0)
{
System.exit(0);
}
}
}
public static void main(String args[])
{
chuanqi one = new chuanqi();
Font ft=new Font("宋体",Font.PLAIN,12);
UIManager.put("MenuItem.font",ft);
UIManager.put("Menu.font",ft);
UIManager.put("Label.font",ft);
UIManager.put("CheckBoxMenuItem.font",ft);
UIManager.put("CheckBox.font",ft);
UIManager.put("Button.font",ft);
}
}