解决方案 »
- smpp短信网关 的问题 没分了
- 一个很简单的问题,有4个错误
- Swing 组件问题
- 问题1:如何在单击确认前一直循环。问题2:如何每隔一定时间去执行一个方法
- 求 SQL Server jar包的 说明文档 -_-|||
- 有没有Jakarta Commons API可以下载到?
- 问个问题,本人想搞java怎么办??(给分)
- init() destroy()方法为什么会多次被调用?
- 使用 Forte 的一个小问题
- linux server + mysql + jdk_linux真正适合中国人的开发方案
- 高手请进!关于一个二分插入排序的问题。。
- java 01000 输出时自动转换为8进制 希望是1000,
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;import javax.swing.ImageIcon;
import javax.swing.JOptionPane;public class Gui10 extends Panel {
public Gui10(String title) {
Frame frame = new Frame(title);
frame.setSize(200, 400); //设置窗口大小,200px*400px
frame.setLocationRelativeTo(null);// 将窗口置于屏幕的中央
frame.setBackground(Color.GREEN);//设置窗口背景颜色
frame.setResizable(false);// 设置窗体大小不能调整
frame.setIconImage(new ImageIcon("C:/Users/hp-/Documents/"
+ "美图图库/Snapshot_20131024_1_副本.jpg").getImage());//设置窗口显示的图像
// frame.setUndecorated(true); init();//调用init()
frame.add(this);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// if(JOptionPane.showConfirmDialog(null, "退出","确定关闭吗?",
// JOptionPane.YES_NO_OPTION,JOptionPane
// .QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
System.exit(0);
// }
}
});
} private void init() {
final TextArea textArea = new TextArea(10, 20);
textArea.setBackground(Color.CYAN); //设置背景色为青色
textArea.setText("hello,fkjava");//设置文本内容
// textArea.setIgnoreRepaint(isEnabled());
this.add(textArea);//将这个区域添加到上面的窗口 Label label = new Label("用户名:", Label.RIGHT); //新建一个"用户名",右对齐
this.add(label);//添加到窗口
final TextField userName = new TextField(10);//新建一个文本框,这个是用来输入"用户名"的
userName.setEchoChar('*');//设置显示内容为"*",就是输入的用户名显示为"*"
this.add(userName);//添加到窗口
Label label2 = new Label("密 码:", Label.RIGHT);//新建一个"密码",右对齐
this.add(label2);//添加到窗口
final TextField userPassword = new TextField(10);;//新建一个文本框,这个是用来输入"密码"的
userPassword.setEchoChar('*');//设置显示内容为"*",就是输入的密码显示为"*"
this.add(userPassword);//添加到窗口
Button loginBtn = new Button("登录");//添加一个"登陆"按钮
loginBtn.addActionListener(new ActionListener() { //这是对“登陆”按钮的一些操作
public void actionPerformed(ActionEvent e) { // 点击"登陆时",触发该事件
if (userName.getText().trim().length() == 0
|| userPassword.getText().trim().length() == 0) { // 如果"用户名"和"密码",去掉前后的空格为空
JOptionPane.showMessageDialog(null, "用户名密码不允许为空"); //弹出一个对话框,提示"用户名密码不允许为空"
// return;
textArea.setText(""); //清空窗口的内容
} else if (userName.getText().trim().equals("1")
&& userPassword.getText().trim().equals("1")) {// 如果用户名和密码,去掉前后的空格为"1"
JOptionPane.showMessageDialog(null, "登录成功");//弹出一个对话框,提示"登录成功"
textArea.setText("您输入的用户名是:" + userName.getText() + "\n"
+ "您输入的密码是:" + userPassword.getText());//在窗口中显示"您输入的用户名是:","您输入的密码是:"
userName.setText("");//清空"用户名"对应的文本框
userPassword.setText("");//清空"密码"对应的文本框 // System.exit(0);
} else {
JOptionPane.showMessageDialog(null, "用户名或密码错误");//弹出一个对话框,提示"用户名或密码错误"
textArea.setText("您输入的用户名是:" + userName.getText() + "\n"
+ "您输入的密码是:" + userPassword.getText());//在窗口中显示"您输入的用户名是:","您输入的密码是:"
userName.setText("");//清空"用户名"对应的文本框
userPassword.setText("");//清空"密码"对应的文本框 }
}
});
loginBtn.setBackground(Color.blue);//设置"登陆"按钮为蓝色
Button resetBtn = new Button("退出");//添加一个"退出"按钮
resetBtn.setBackground(Color.RED);//设置"退出"按钮为红色
this.add(loginBtn);//添加"登陆"按钮到窗口
this.add(resetBtn);//添加"退出"按钮到窗口
resetBtn.addActionListener(new ActionListener() {//"退出"按钮的一些操作
/*
* 点击"退出"时弹出一个对话框,提示"退出", "确定关闭吗?"点击"是",停掉虚拟机,退出程序。点击"否",退回到原界面
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
if (JOptionPane
.showConfirmDialog(null, "退出", "确定关闭吗?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
System.exit(0);
} } });
// 做了4个复选框,默认选中"看大美女"
Checkbox hooby1 = new Checkbox("看书");
Checkbox hooby2 = new Checkbox("看小美女");
Checkbox hooby3 = new Checkbox("看美女");
Checkbox hooby4 = new Checkbox("看大美女", true);
// 将4个复选框添加到窗口
this.add(hooby1);
this.add(hooby2);
this.add(hooby3);
this.add(hooby4);
// 也是复选框的一种,只能选中一个,默认为"男"
CheckboxGroup cg = new CheckboxGroup();
Checkbox sex = new Checkbox("男", true, cg);
Checkbox sex2 = new Checkbox("女", false, cg);
// 将2个复选框添加到窗口
this.add(sex);
this.add(sex2);
Choice choice = new Choice(); // 新建一个下拉列表
choice.addItemListener(new ItemListener() {
// 剩下的操作跟上面的差不多,自己看下吧
public void itemStateChanged(ItemEvent e) {
final Dialog dialog = new Dialog(null, "对话框",
Dialog.DEFAULT_MODALITY_TYPE);
// dialog.setTitle("你好");
dialog.setLocationRelativeTo(null);
dialog.setResizable(false);
dialog.setSize(10, 100);
dialog.setBackground(Color.RED);
dialog.add(new Label(e.getItem().toString()));
Button ok = new Button("您选择的是:" + e.getItem().toString());
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "确定关闭吗?");
dialog.setVisible(false); }
});
dialog.add(ok);
dialog.setVisible(true);
}
});
choice.addItem("小学");
choice.addItem("中学");
choice.addItem("大学");
choice.addItem("没学");
this.add(choice); } public static void main(String[] args) {
new Gui10("注册");
}}注释写的差不多了,楼主自己看吧