黑马程序员技术交流社区
标题:
gui
[打印本页]
作者:
fmi110
时间:
2015-9-15 08:52
标题:
gui
a
package com.fmi110;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class FrameDemo6 {
/**
* 创建一个文本框,只能输入数字,非数字输入不显示
*/
public static void main(String[] args) {
// 建立方框
Frame f = new Frame("QQ");
//设置边界
f.setBounds(100,100,300,200);
//设置布局
f.setLayout(new FlowLayout());
//设置可见
f.setVisible(true);
//设置窗口关闭监听
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.out.println("关闭窗口");
System.exit(0);
}
});
//文本框
final TextField tf = new TextField(20);
//按钮
Button b = new Button("清除");
//标签
Label l = new Label("输入QQ号,只能是数字~~");
//添加组件
f.add(l);
f.add(tf);
f.add(b);
//给按钮添加鼠标事件
b.addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent e) {
// public void mouseReleased(MouseEvent e){
System.out.println("mouseReleased");
}
@Override
public void mousePressed(MouseEvent e) {
// public void mousePressed(MouseEvent e){
System.out.println("mousePressed");
}
@Override
public void mouseExited(MouseEvent e) {
// mouseExited(MouseEvent e)
System.out.println("mouseExited");
}
@Override
public void mouseEntered(MouseEvent e) {
// mouseEntered(MouseEvent e)
System.out.println("mouseEntered");
}
@Override
public void mouseClicked(MouseEvent e) {
// mouseClicked(MouseEvent e)
String s = null;
s = tf.getText();
tf.setText("");
tf.requestFocus();//获取光标
System.out.println("mouseClicked:"+s);
}
});
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2