1. 怎么用java写一个界面怎么用java写一个界面 新建一个窗口 , 然后实现一个关闭按钮”窗口的功能
import java.awt.*;
import java.awt.event.*;
public class TestWindowEvent {
public static void main (String[] args) {
new Frame88 ("WindowAdapter");
}
}
class Frame88 extends Frame {
Frame88 (String s) {
super(s);
setBounds (300,300,200,70);
setLayout (null);
setVisible (true);
addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible (false);
System.exit(0);
}
} );
}
}
2. 用java写界面注册怎么写 package com.demo.client;import java.awt.GridLayout;import java.awt.Toolkit;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import javax.swing.*; public class RegistFrame extends JFrame implements ActionListener{ String serverIp = null; int port = 0; String strSex = ""; int PswProtectNum; String area = ""; JLabel labUserId; JLabel labChatname; JLabel labPsw; JLabel labRePsw; JLabel labPswQst; JLabel labPswAns; JLabel labAge; JLabel labArea; JLabel labSex; JTextField txtUserID; JTextField txtChatname; JPasswordField txtPsw; JPasswordField txtRePsw; JComboBox comPswQst; JTextField txtPswAns; JTextField txtAge; JComboBox comArea; JRadioButton rad1,rad2,rad3; JButton btnSubmit; JButton btnCancel; JPanel p0,p1,p3,p4,p5,p6,p7,p8,p9,p10; ItemListener listener1 = new ItemListener() { public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub JRadioButton button = (JRadioButton)e.getItemSelectable(); if (button == rad1)strSex = "男"; if (button == rad2)strSex = "女"; if (button == rad3)strSex = ""; } }; ItemListener listener2 = new ItemListener() { public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub JComboBox box = (JComboBox)e.getItemSelectable(); if(box == comPswQst){ PswProtectNum = comPswQst.getSelectedIndex(); } if(box == comArea){ area = comArea.getSelectedItem().toString(); } } }; public RegistFrame(String serverIp,int port) { this.serverIp = serverIp; this.port = port; p0 = new JPanel(); labUserId = new JLabel("*帐号:"); txtUserID = new JTextField(20); txtUserID.setEditable(true); p0.add(labUserId); p0.add(txtUserID); p1 = new JPanel(); labChatname = new JLabel("*昵称:"); txtChatname = new JTextField(20); txtChatname.setEditable(true); p1.add(labChatname); p1.add(txtChatname); p3 = new JPanel(); labPsw = new JLabel("*请输入密码:"); txtPsw = new JPasswordField(20); p3.add(labPsw); p3.add(txtPsw); p4 = new JPanel(); labRePsw = new JLabel("*请再次输入密码:"); txtRePsw = new JPasswordField(20); p4.add(labRePsw); p4.add(txtRePsw); p5 = new JPanel(); labPswQst = new JLabel("请设定密码保护问题:"); String [] strQst = { "" , "您母亲的姓名是?" , "您父亲的职业是?" , "您配偶的生日是?" , "您的学号(工号)是?" , "您母亲的生日是?" , "您高中班主任的姓名是?" , "您父亲的姓名是?" , "您的出生地是?" , "您小学班主任的姓名是?" , "您配偶的姓名是?" }; comPswQst = new JComboBox(strQst); comPswQst.addItemListener(listener2); p5.add(labPswQst); p5.add(comPswQst); p6 = new JPanel(); labPswAns = new JLabel("请设定密码保护答案:"); txtPswAns = new JTextField(20); p6.add(labPswAns); p6.add(txtPswAns); p7 = new JPanel(); labAge = new JLabel("您的性别是:"); rad1 = new JRadioButton("我是帅哥!"); rad1.addItemListener(listener1); rad2 = new JRadioButton("我是美女!"); rad2.addItemListener(listener1); rad3 = new JRadioButton("我不告诉你!"); rad3.addItemListener(listener1); ButtonGroup group = new ButtonGroup(); group.add(rad1); group.add(rad2); group.add(rad3); p7.add(labAge); p7.add(rad1); p7.add(rad2); p7.add(rad3); p8 = new JPanel(); labArea = new JLabel("请选择您的地区:"); String [] strArea = { "我是南方人" , "我是北方人" , "我是东北人" , "我是西北人" , "我是西南人" }; comArea = new JComboBox(strArea); comArea.addItemListener(listener2); p8.add(labArea); p8.add(comArea); p9 = new JPanel(); labAge = new JLabel("您的年龄是:"); txtAge = new JTextField(15); p9.add(labAge); p9.add(txtAge); p10 = new JPanel(); btnSubmit = new JButton("提交"); btnSubmit.addActionListener(this); btnCancel = new JButton("取消"); btnCancel.addActionListener(this); p10.add(btnSubmit); p10.add(btnCancel); getContentPane().setLayout(new GridLayout(10,1)); getContentPane().add(p0); getContentPane().add(p1); getContentPane().add(p3); getContentPane().add(p4); getContentPane().add(p5); getContentPane().add(p6); getContentPane().add(p7); getContentPane().add(p8); getContentPane().add(p9); getContentPane().add(p10); setTitle("注册新用户"); pack(); setResizable(false); setDefaultCloseOperation(RegistFrame.DISPOSE_ON_CLOSE); Toolkit tk=Toolkit.getDefaultToolkit(); setLocation((tk.getScreenSize().width-getSize().width)/2,(tk.getScreenSize().height-getSize().height)/2); setVisible(true); } public void。