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. ARM工作模式寻址

    用户模式(User)                 usr 快速中断模式(FIQ) fiq 普通终端模式(IRQ)     irq 保护模式(Supervisor) svc 数据访问终止模式(Abo ...

  2. 自动化运维——HelloWorld(一)

    1.HelloWorld vi first_shell.sh #!/bin/bash #Filename: first_shell.sh #auto echo hello world! #by aut ...

  3. PAT Basic 1042 字符统计 (20 分)

    请编写程序,找出一段给定文字中出现最频繁的那个英文字母. 输入格式: 输入在一行中给出一个长度不超过 1000 的字符串.字符串由 ASCII 码表中任意可见字符及空格组成,至少包含 1 个英文字母, ...

  4. At grand 024

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

  5. 页面渲染机制(一、DOM和CSSOM树的构建)

    1.HTML的加载 HTML是一个网页的基础,下载完成后解析 2.其他静态资源加载 解析HTML时,发现其中有其他外部资源链接比如CSS.JS.图片等,会立即启用别的线程下载. 但当外部资源是JS时, ...

  6. 分组统计 over(partition by

    sum( CASE WHEN ISNULL(b.zl, 0) = 0 THEN C.LLZL ELSE b.zl END * c.pccd * b.sl) over(partition by b.dj ...

  7. k8-s存储

    原文 https://mp.weixin.qq.com/s/6yg_bt5mYKWdXS0CidY6Rg 从用户角度看,存储就是一块盘或者一个目录,用户不关心盘或者目录如何实现,用户要求非常" ...

  8. 函数中的this与 this.prototype

    函数中的this添加函数是加在对象上,而this.prototype是添加在原型上,通过prototype的指向来一级一级查找 prototype是构造函数访问原型对象,__proto__是对象实例访 ...

  9. luogu 4366 [Code+#4]最短路 Dijkstra + 位运算 + 思维

    这个题思路十分巧妙,感觉很多题都有类似的套路. 我们发现异或操作其实就是将一个数的二进制的若干个 $0$ 变成 $1$,或者一些 $1$ 变成 $0$. 而每次按照某种顺序一位一位地异或也可以起到同时 ...

  10. 【gym102394B】Binary Numbers(DP)

    题意:From https://blog.csdn.net/m0_37809890/article/details/102886956 思路: 可以发现转移就是右上角的一个区间前缀和 std只要开1倍 ...