dupengframe.java
来自「简单的Java的图形界面设计。没太大技术含量。」· Java 代码 · 共 571 行 · 第 1/2 页
JAVA
571 行
import java.awt.GraphicsConfiguration;
import java.awt.HeadlessException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JSpinner;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import javax.swing.text.BadLocationException;
import javax.swing.JCheckBox;
import javax.swing.JTextArea;
import javax.swing.JEditorPane;
import javax.swing.BorderFactory;
import java.awt.Color;
import javax.swing.border.TitledBorder;
import java.awt.TextField;
import java.awt.Panel;
/**
* <p>Title: </p>
*
* <p>Description:first gui design </p>
*
* <p>Copyright: dupengCopyright (c) 2007</p>
*
* <p>Company: hit werun</p>
*
* @author not attributable
* @version 1.0
*/
public class dupengframe extends JFrame {
/*declare database*/
private String heroName[];
private String heroPassword[];
private String inputName;
private String inputPassword;
private int flag=0;
private String section;
private String race;
private String weapon[];
public dupengframe() throws HeadlessException {
super();
initDataBase();
try {
jbInit();
} catch (Exception ex) {
ex.printStackTrace();
}
}
/*init database*/
public void initDataBase()
{
heroName=new String[3];
heroPassword=new String[3];
weapon=new String[3];
heroName[0]="dupeng";
heroName[1]="chacha";
heroName[2]="lee";
heroPassword[0]="11";
heroPassword[1]="22";
heroPassword[2]="33";
weapon[0]="";
weapon[1]="";
weapon[2]="";
}
public dupengframe(GraphicsConfiguration gc) {
super(gc);
}
public dupengframe(String title) throws HeadlessException {
super(title);
}
public dupengframe(String title, GraphicsConfiguration gc) {
super(title, gc);
}
public static void main(String[] args) {
dupengframe dupengframe = new dupengframe();
}
/*init*/
private void jbInit() throws Exception {
jButton1.setBounds(new Rectangle(193, 272, 90, 23));
jButton1.setNextFocusableComponent(jButton2);
jButton1.setToolTipText("");
jButton1.setText("大侠来过");
jButton1.addKeyListener(new dupengframe_jButton1_keyAdapter(this));
jButton1.addMouseListener(new dupengframe_jButton1_mouseAdapter(this));
jButton2.setBounds(new Rectangle(298, 272, 89, 23));
jButton2.setNextFocusableComponent(jTextField1);
jButton2.setText("大侠告辞");
jButton2.addActionListener(new dupengframe_jButton2_actionAdapter(this));
jLabel2.setText("大侠之名");
jLabel2.setBounds(new Rectangle(23, 64, 64, 15));
jTextField1.setNextFocusableComponent(textField1);
jTextField1.setText("在这儿输入大侠的用户名");
jTextField1.setBounds(new Rectangle(95, 63, 143, 20));
//jTextField1.addKeyListener(new dupengframe_jTextField1_keyAdapter(this));
jTextField1.addMouseListener(new dupengframe_jTextField1_mouseAdapter(this));
jLabel3.setText("大侠之诀");
jLabel3.setBounds(new Rectangle(23, 106, 64, 15));
jLabel4.setText("大侠选族");
jLabel4.setBounds(new Rectangle(295, 63, 57, 15));
jRadioButton1.setNextFocusableComponent(jRadioButton2);
jRadioButton1.setText("人族");
jRadioButton1.setBounds(new Rectangle(294, 89, 77, 23));
jRadioButton1.addActionListener(new
dupengframe_jRadioButton1_actionAdapter(this));
jRadioButton2.setNextFocusableComponent(jRadioButton5);
jRadioButton2.setText("拐族");
jRadioButton2.setBounds(new Rectangle(294, 121, 77, 23));
jRadioButton2.addActionListener(new
dupengframe_jRadioButton2_actionAdapter(this));
jLabel6.setText("大侠选区");
jLabel6.setBounds(new Rectangle(132, 165, 73, 15));
jRadioButton3.setNextFocusableComponent(jRadioButton4);
jRadioButton3.setText("电信区");
jRadioButton3.setBounds(new Rectangle(132, 190, 96, 23));
jRadioButton3.addActionListener(new
dupengframe_jRadioButton3_actionAdapter(this));
jRadioButton4.setNextFocusableComponent(jTextArea1);
jRadioButton4.setText("网通区");
jRadioButton4.setBounds(new Rectangle(248, 190, 96, 23));
jRadioButton4.addActionListener(new
dupengframe_jRadioButton4_actionAdapter(this));
jRadioButton5.setNextFocusableComponent(jCheckBox1);
jRadioButton5.setText("渣族");
jRadioButton5.setBounds(new Rectangle(294, 156, 77, 23));
jRadioButton5.addActionListener(new
dupengframe_jRadioButton5_actionAdapter(this));
jLabel1.setBounds(new Rectangle(97, 7, 242, 15));
jLabel5.setBounds(new Rectangle(140, 140, 0, 0));
jLabel8.setText("大侠选器");
jLabel8.setBounds(new Rectangle(23, 144, 64, 15));
jCheckBox1.setNextFocusableComponent(jCheckBox2);
jCheckBox1.setText("瑞士军刀");
jCheckBox1.setBounds(new Rectangle(17, 175, 85, 23));
jCheckBox1.addActionListener(new dupengframe_jCheckBox1_actionAdapter(this));
jCheckBox2.setNextFocusableComponent(jCheckBox3);
jCheckBox2.setText("54式手枪");
jCheckBox2.setBounds(new Rectangle(18, 214, 85, 23));
jCheckBox2.addActionListener(new dupengframe_jCheckBox2_actionAdapter(this));
jCheckBox3.setNextFocusableComponent(jRadioButton3);
jCheckBox3.setText("俺家拖鞋");
jCheckBox3.setBounds(new Rectangle(17, 250, 85, 23));
jCheckBox3.addActionListener(new dupengframe_jCheckBox3_actionAdapter(this));
jTextArea1.setBorder(BorderFactory.createLoweredBevelBorder());
jTextArea1.setNextFocusableComponent(jButton1);
jTextArea1.setCaretColor(Color.white);
jTextArea1.setText("");
jTextArea1.setBounds(new Rectangle(100, 214, 282, 42));
textField1.setText("在这儿输入大侠的密码");
textField1.setBounds(new Rectangle(95, 105, 143, 23));
textField1.addMouseListener(new dupengframe_textField1_mouseAdapter(this));
textField1.addKeyListener(new dupengframe_textField1_keyAdapter(this));
this.getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
jLabel1.setText(" 九州云荒之重现江湖 ");
jPanel1.setLayout(null);
buttonGroup1.add(jRadioButton3);
buttonGroup1.add(jRadioButton4);
buttonGroup2.add(jRadioButton1);
buttonGroup2.add(jRadioButton2);
buttonGroup2.add(jRadioButton5);
jPanel1.add(jLabel5, null);
jPanel1.add(jLabel4, null);
jPanel1.add(jRadioButton5, null);
jPanel1.add(jLabel2, null);
jPanel1.add(jLabel1, null);
jPanel1.add(jTextField1, null);
jPanel1.add(jRadioButton1, null);
jPanel1.add(jRadioButton2, null);
jPanel1.add(jButton1, null);
jPanel1.add(jButton2, null);
jPanel1.add(jRadioButton3, null);
jPanel1.add(jRadioButton4, null);
jPanel1.add(jTextArea1);
jPanel1.add(jLabel8);
jPanel1.add(jCheckBox1);
jPanel1.add(jCheckBox2);
jPanel1.add(jCheckBox3);
jPanel1.add(textField1);
jPanel1.add(jLabel3, null);
jPanel1.add(jLabel6, null);
race="人族";
section="电信区";
}
/*create useful components*/
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JButton jButton1 = new JButton();
JButton jButton2 = new JButton();
JLabel jLabel2 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel3 = new JLabel();
JRadioButton jRadioButton1 = new JRadioButton("",true);
JRadioButton jRadioButton2 = new JRadioButton("",false);
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JRadioButton jRadioButton3 = new JRadioButton("",true);
JRadioButton jRadioButton4 = new JRadioButton("",false);
JRadioButton jRadioButton5 = new JRadioButton("",false);
ButtonGroup buttonGroup1 = new ButtonGroup();
ButtonGroup buttonGroup2 = new ButtonGroup();
JLabel jLabel8 = new JLabel();
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
JTextArea jTextArea1 = new JTextArea();
TitledBorder titledBorder1 = new TitledBorder("");
TextField textField1 = new TextField();
public void jButton2_actionPerformed(ActionEvent e) {
System.exit(0);
}
/*useful events handler*/
public void jRadioButton1_actionPerformed(ActionEvent e) {
if(jRadioButton1.isSelected())
{
race ="人族";
}
}
public void jRadioButton2_actionPerformed(ActionEvent e) {
if(jRadioButton2.isSelected())
{
race="拐族";
}
}
public void jRadioButton3_actionPerformed(ActionEvent e) {
if(jRadioButton3.isSelected())
{
section="电信区";
}
}
public void jRadioButton5_actionPerformed(ActionEvent e) {
if(jRadioButton5.isSelected())
{
race="渣族";
}
}
public void jButton1_mouseClicked(MouseEvent e) {
inputName=jTextField1.getText();
inputPassword= textField1.getText();
for(int i=0;i<3;i++)
{
if(heroName[i].equals(inputName))
{
if(heroPassword[i].equals(inputPassword))
{
/*show that you can enter*/
flag=1;
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?