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的更多相关文章

  1. 郝斌老师的SQL教程

    时隔两年,重拾数据库编程.郝斌老师的sql教程通俗易懂,用作复习简直不能太赞.

  2. 郝斌老师C语言学习笔记(一)

    在给变量分配内存时,很可能这段内存存在以前其他程序使用留下的值.当使用VC编译器,若编译器发现没有给变量赋值而使用,就会返回一个以“85”开头的很大的数字(此时该段内存中为一个垃圾数,为了避免出现较常 ...

  3. [C]郝斌C语言课程大纲及笔记

    本笔记整理于郝斌老师C语言课程,做学习参考之用. 1.[编程笔记]第一章 C语言概述 2.[编程笔记]第二章 C语言预备知识 3.[编程笔记]第三章 运算符与表达式 4.[编程笔记]第四章 流程控制 ...

  4. 郝斌–SQL Server2005学习笔记

    数据库(Database)狭义上是指存储数据的仓库,广义上包含对数据进行存储和管理的软件(DBMS)和数据本身.数据库由表.关系和操作组成. 一.数据库简介 1.为什么需要数据库 数据库简化了对数据的 ...

  5. 郝斌C语言代码

    #include<stdio.h> int main() { ; printf("%#x\n",a); ; } /* output 0xf; */ //(15)10= ...

  6. 郝斌 SqlServer2005 学习笔记

    1.0 什么是数据库 狭义:存储数据的仓库. 广义:可以对数据进行存储和管理的软件以及数据本身统称为数据库. 另外一种说法:数据库是由表.关系.操作组成. 2.0 为什么要学习数据库 几乎所有的应用软 ...

  7. C语言-郝斌笔记-007是否为素数

    是否为素数 # include <stdio.h> bool IsPrime(int val) { int i; ; i<val; ++i) { ) break; } if (i = ...

  8. C语言-郝斌笔记-006排序及查找

    1. int partion(int *a, int low, int high) { int value = a[low]; int t; while (low < high) { while ...

  9. C语言-郝斌笔记-005菲波拉契序列

    菲波拉契序列 /* 菲波拉契序列 1 2 3 5 8 13 21 34 */ # include <stdio.h> int main(void) { int n; int f1, f2, ...

随机推荐

  1. Codeforces 990 调和级数路灯贪心暴力 DFS生成树两子树差调水 GCD树连通块暴力

    A 水题 /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) using namespace ...

  2. java知识

    DiskFileUploadhttps://blog.csdn.net/FightingITPanda/article/details/79742631 import java.util.ArrayL ...

  3. Redis数据类型之散列表

    Redis五大数据类型以及操作 目录: 一.redis的两种链接方式 二.redis的字符串操作(string) 三.redis的列表操作(list) 四.redis的散列表操作(类似于字典里面嵌套字 ...

  4. TF-epoch、 iteration和batchsize区别(转载)

    from http://www.cnblogs.com/qggg/p/6876942.html 转自 http://blog.csdn.net/sinat_30071459/article/detai ...

  5. 输出到Excel

    HSSFWorkbook oBook = new HSSFWorkbook(); NPOI.SS.UserModel.ISheet oSheet = oBook.CreateSheet(); #reg ...

  6. Let Us Adore 让我们来敬拜祂 中文歌词

      Verse 1 诸天宣告 神的荣耀 万国万民 都将赞美 宣扬祂奇妙 The heavens declare The glory of God And all of the world Will j ...

  7. Vue组件创建和组件传值

    Vue创建组件的方式 使用Vue.Extend()和Vue.component全局注册组件 首先我们定义一个组件并接收 var com1 =Vue.extend({ template:"&l ...

  8. js-展开评论与隐藏评论

    //控制展开评论和隐藏评论 controldiscuss(){ $(".opendiss").click(function(){ if($(this).context.innerH ...

  9. cpu、gpu 安装框架pytorch,cntk,theano及测试

    一,cpu 下安装 tensorflow conda env list source activate tensorflow 直接安装相应版本 python import tensorflow as ...

  10. CF191C Fools and Roads - 树剖解法

    Codeforces Round #121 (Div. 1) C. Fools and Roads time limit per test :2 seconds memory limit per te ...