郝斌_GUI
85事件处理
import java.awt.Button;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; class A implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("hello");
}
} public class Test {
public static void main(String[] args) { Frame f = new Frame("haha");
Button bn = new Button("ok");
f.add(bn);
A aa = new A(); bn.addActionListener(aa); f.pack();
f.setVisible(true); // 适配器,设置窗体可以关闭
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
87十个按钮的设计
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; public class Test {
public static void main(String[] args) {
Frame f = new Frame();
f.setSize(300, 300);
f.setLayout(new GridLayout(2, 1));// 2行1列 Panel p1 = new Panel();
p1.setLayout(new BorderLayout());
Panel p1_1 = new Panel();
p1_1.setLayout(new GridLayout(2, 1));// 2行1列
Button bn1 = new Button("BUTTON1");
Button bn2 = new Button("BUTTON2");
Button bn3 = new Button("BUTTON3");
Button bn4 = new Button("BUTTON4");
p1.add(bn1, BorderLayout.WEST);
p1_1.add(bn3);
p1_1.add(bn4);
p1.add(p1_1, BorderLayout.CENTER);
p1.add(bn2, BorderLayout.EAST); Panel p2 = new Panel();
p2.setLayout(new BorderLayout());
Panel p2_1 = new Panel();
p2_1.setLayout(new GridLayout(2, 2));// 2行2列
Button bn5 = new Button("BUTTON5");
Button bn6 = new Button("BUTTON6");
Button bn7 = new Button("BUTTON7");
Button bn8 = new Button("BUTTON8");
Button bn9 = new Button("BUTTON9");
Button bn10 = new Button("BUTTON10");
p2.add(bn5, BorderLayout.WEST);
p2_1.add(bn7);
p2_1.add(bn8);
p2_1.add(bn9);
p2_1.add(bn10);
p2.add(p2_1, BorderLayout.CENTER);
p2.add(bn6, BorderLayout.EAST); f.add(p1);
f.add(p2);
f.pack();
f.setVisible(true); // 适配器,设置窗体可以关闭
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
88三个文本框的相加运算示例
89内部类 匿名类
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.WindowAdapter;
import java.awt.event.WindowEvent; class TF {
public static TextField tf1, tf2, tf3; public void launch() {
Frame f = new Frame();
tf1 = new TextField(30);
tf2 = new TextField(30);
tf3 = new TextField(30);
Button bn = new Button("=");
Label lb = new Label("+"); f.setLayout(new FlowLayout());
f.add(tf1);
f.add(lb);
f.add(tf2);
f.add(bn);
f.add(tf3); bn.addActionListener(new MyMoniter()); f.pack();
f.setVisible(true); // 适配器,设置窗体可以关闭
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} class MyMoniter implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
int num1 = Integer.parseInt(tf1.getText());
int num2 = Integer.parseInt(tf2.getText());
int num3 = num1 + num2; Integer it = new Integer(num3);
String str3 = it.toString(); tf3.setText(str3);
}
}
} public class Test {
public static void main(String[] args) {
new TF().launch();
}
}
郝斌_GUI的更多相关文章
- 郝斌老师的SQL教程
时隔两年,重拾数据库编程.郝斌老师的sql教程通俗易懂,用作复习简直不能太赞.
- 郝斌老师C语言学习笔记(一)
在给变量分配内存时,很可能这段内存存在以前其他程序使用留下的值.当使用VC编译器,若编译器发现没有给变量赋值而使用,就会返回一个以“85”开头的很大的数字(此时该段内存中为一个垃圾数,为了避免出现较常 ...
- [C]郝斌C语言课程大纲及笔记
本笔记整理于郝斌老师C语言课程,做学习参考之用. 1.[编程笔记]第一章 C语言概述 2.[编程笔记]第二章 C语言预备知识 3.[编程笔记]第三章 运算符与表达式 4.[编程笔记]第四章 流程控制 ...
- 郝斌–SQL Server2005学习笔记
数据库(Database)狭义上是指存储数据的仓库,广义上包含对数据进行存储和管理的软件(DBMS)和数据本身.数据库由表.关系和操作组成. 一.数据库简介 1.为什么需要数据库 数据库简化了对数据的 ...
- 郝斌C语言代码
#include<stdio.h> int main() { ; printf("%#x\n",a); ; } /* output 0xf; */ //(15)10= ...
- 郝斌 SqlServer2005 学习笔记
1.0 什么是数据库 狭义:存储数据的仓库. 广义:可以对数据进行存储和管理的软件以及数据本身统称为数据库. 另外一种说法:数据库是由表.关系.操作组成. 2.0 为什么要学习数据库 几乎所有的应用软 ...
- C语言-郝斌笔记-007是否为素数
是否为素数 # include <stdio.h> bool IsPrime(int val) { int i; ; i<val; ++i) { ) break; } if (i = ...
- C语言-郝斌笔记-006排序及查找
1. int partion(int *a, int low, int high) { int value = a[low]; int t; while (low < high) { while ...
- C语言-郝斌笔记-005菲波拉契序列
菲波拉契序列 /* 菲波拉契序列 1 2 3 5 8 13 21 34 */ # include <stdio.h> int main(void) { int n; int f1, f2, ...
随机推荐
- java.lang.ClassNotFoundException: org.apache.jsp.login_jsp
<span style="font-family: Simsun; background-color: rgb(255, 255, 255);">想必大家在用Eclip ...
- sql 占位符及部分时间函数
Mysql 预处理占位符 %s -- 表示字段串 %d -- 表示整形数字 %f -- 表示浮点数 (UNIX_TIMESTAMP(DATE_SUB(now(), INTERVAL jp_days D ...
- java.lang.Integer 类(JDK1.7)
1.Integer 和int 的区别 ①.Integer 是 int 包装类,int 是八大基本数据类型之一(byte,char,short,int,long,float,double,boolean ...
- 对所有的webview添加userAgent
在appdelegate中- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDicti ...
- VUE+DJANGO
1.router类型不能设置为history const router = new Router({ mode: '', routes, }); //避免打包到django后刷新报错 2.样式放sta ...
- Java并发编程实战 第5章 构建基础模块
同步容器类 Vector和HashTable和Collections.synchronizedXXX 都是使用监视器模式实现的. 暂且不考虑性能问题,使用同步容器类要注意: 只能保证单个操作的同步. ...
- Linux系统中的硬件问题如何排查?(3)
Linux系统中的硬件问题如何排查?(3) 2013-03-27 10:32 核子可乐译 51CTO.com 字号:T | T 在Linux系统中,对于硬件故障问题的排查可能是计算机管理领域最棘手的工 ...
- java数据结构5--集合Map
Map Map与Collection在集合框架中属并列存在 Map存储的是键值对<K,V> Map存储元素使用put方法,Collection使用add方法 Map集合没有直接取出元素的方 ...
- C++常用速查
int main() { int arr[2][5] = { {1,8,12,20,25}, {5,9,13,24,26} }; } void f(double p[][10]) { } #inclu ...
- linux常用的镜像(centos、kali、redhat等)官方下载地址
常用的linux版本: Redhat:https://developers.redhat.com/topics/linux/ Centos:https://www.centos.org/downloa ...