给位老大,求助一个AWT的初级编程: 很简单的,建议楼主自己动手,找本awt书看看就ok了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 satangf(好好学习,天天向上!) 大哥,我也知道这个应该是很简单的,但现在急需,劳驾大哥编写一下,小弟感不尽.........,最好有简单的程序注释,劳驾大哥了,小弟一定放分! import java.awt.*;import java.awt.event.*;import java.util.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: </p> * @author not attributable * @version 1.0 */public class TestFrame extends Frame { public static Hashtable has = new Hashtable(); Button button1 = new Button(); Button button2 = new Button(); TextArea textArea1 = new TextArea(); Button button3 = new Button(); public TestFrame() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { TestFrame testFrame = new TestFrame(); testFrame.show(); testFrame.setSize(new Dimension(400, 250)); } private void jbInit() throws Exception { button1.setLabel("登记"); button1.setBounds(new Rectangle(80, 193, 71, 25)); button1.addActionListener(new TestFrame_button1_actionAdapter(this)); this.setLayout(null); button2.setBounds(new Rectangle(164, 193, 71, 25)); button2.addActionListener(new TestFrame_button2_actionAdapter(this)); button2.setLabel("查看"); textArea1.setEditable(false); textArea1.setText(""); textArea1.setBounds(new Rectangle(68, 25, 255, 152)); button3.setLabel("关闭"); button3.addActionListener(new TestFrame_button3_actionAdapter(this)); button3.setBounds(new Rectangle(250, 193, 71, 25)); this.setResizable(false); this.add(textArea1, null); this.add(button2, null); this.add(button1, null); this.add(button3, null); } void button1_actionPerformed(ActionEvent e) { IDFrame idf = new IDFrame(); idf.show(); idf.setSize(new Dimension(350, 180)); } void button2_actionPerformed(ActionEvent e) { textArea1.setText(""); Enumeration en = has.keys(); while (en.hasMoreElements()) { String id = en.nextElement().toString(); textArea1.append("ID:" + id + " Name:" + has.get(id).toString() + '\n'); } } void button3_actionPerformed(ActionEvent e) { System.exit(0); } class IDFrame extends Frame { Label label1 = new Label(); TextField textField1 = new TextField(); Label label2 = new Label(); TextField textField2 = new TextField(); Button button1 = new Button(); Button button2 = new Button(); public IDFrame() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } private void jbInit() throws Exception { label1.setText("学生 ID:"); label1.setBounds(new Rectangle(52, 38, 61, 16)); this.setLayout(null); textField1.setText(""); textField1.setBounds(new Rectangle(114, 35, 142, 22)); label2.setBounds(new Rectangle(52, 68, 61, 16)); label2.setText("学生姓名:"); textField2.setText(""); textField2.setBounds(new Rectangle(114, 65, 142, 22)); button1.setLabel("确定"); button1.setBounds(new Rectangle(84, 104, 71, 25)); button1.addActionListener(new IDFrame_button1_actionAdapter(this)); button2.setBounds(new Rectangle(166, 104, 71, 25)); button2.addActionListener(new IDFrame_button2_actionAdapter(this)); button2.setLabel("取消"); this.setResizable(false); this.add(button2, null); this.add(label1, null); this.add(label2, null); this.add(textField2, null); this.add(textField1, null); this.add(button1, null); } void button1_actionPerformed(ActionEvent e) { String id = textField1.getText(); String name = textField2.getText(); //这里得到id和name之后你可以放到数据库中,放入数据库的代码自己写,我先放到内存中了。 TestFrame.has.put(id, name); this.dispose(); } void button2_actionPerformed(ActionEvent e) { this.dispose(); } } class IDFrame_button1_actionAdapter implements java.awt.event.ActionListener { IDFrame adaptee; IDFrame_button1_actionAdapter(IDFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button1_actionPerformed(e); } } class IDFrame_button2_actionAdapter implements java.awt.event.ActionListener { IDFrame adaptee; IDFrame_button2_actionAdapter(IDFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button2_actionPerformed(e); } }}class TestFrame_button1_actionAdapter implements java.awt.event.ActionListener { TestFrame adaptee; TestFrame_button1_actionAdapter(TestFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button1_actionPerformed(e); }}class TestFrame_button2_actionAdapter implements java.awt.event.ActionListener { TestFrame adaptee; TestFrame_button2_actionAdapter(TestFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button2_actionPerformed(e); }}class TestFrame_button3_actionAdapter implements java.awt.event.ActionListener { TestFrame adaptee; TestFrame_button3_actionAdapter(TestFrame adaptee) { this.adaptee = adaptee; } public void actionPerformed(ActionEvent e) { adaptee.button3_actionPerformed(e); }} 你把整个类拷贝下来,做成一个类文件,文件名为TestFrame.java然后编译运行就ok了。 (被一道例题难住了)大神们求救啊!!! String类的charAt方法,输出结果正确,但提示。。。。。 SQL查询语句的问题 很简单的一个背景问题。。。 Main class and arguments must be specified怎么解?? 如何提高数据库读写速度? 一个不停止的程序,请教! 乱码问题请高人看看 java.lang.NullPointerException的问题怎么解决? 关于BCB的前途?…… 菜鸟遇到一个设计链表的题,请各位高手帮忙解答下,谢先!! 控制台下怎么输出彩色的文字
import java.awt.event.*;
import java.util.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/public class TestFrame
extends Frame {
public static Hashtable has = new Hashtable();
Button button1 = new Button();
Button button2 = new Button();
TextArea textArea1 = new TextArea();
Button button3 = new Button(); public TestFrame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} public static void main(String[] args) {
TestFrame testFrame = new TestFrame();
testFrame.show();
testFrame.setSize(new Dimension(400, 250));
} private void jbInit() throws Exception {
button1.setLabel("登记");
button1.setBounds(new Rectangle(80, 193, 71, 25));
button1.addActionListener(new TestFrame_button1_actionAdapter(this));
this.setLayout(null);
button2.setBounds(new Rectangle(164, 193, 71, 25));
button2.addActionListener(new TestFrame_button2_actionAdapter(this));
button2.setLabel("查看");
textArea1.setEditable(false);
textArea1.setText("");
textArea1.setBounds(new Rectangle(68, 25, 255, 152));
button3.setLabel("关闭");
button3.addActionListener(new TestFrame_button3_actionAdapter(this));
button3.setBounds(new Rectangle(250, 193, 71, 25));
this.setResizable(false);
this.add(textArea1, null);
this.add(button2, null);
this.add(button1, null);
this.add(button3, null);
} void button1_actionPerformed(ActionEvent e) {
IDFrame idf = new IDFrame();
idf.show();
idf.setSize(new Dimension(350, 180));
} void button2_actionPerformed(ActionEvent e) {
textArea1.setText("");
Enumeration en = has.keys();
while (en.hasMoreElements()) {
String id = en.nextElement().toString();
textArea1.append("ID:" + id + " Name:" + has.get(id).toString() + '\n');
}
} void button3_actionPerformed(ActionEvent e) {
System.exit(0);
} class IDFrame
extends Frame {
Label label1 = new Label();
TextField textField1 = new TextField();
Label label2 = new Label();
TextField textField2 = new TextField();
Button button1 = new Button();
Button button2 = new Button(); public IDFrame() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
label1.setText("学生 ID:");
label1.setBounds(new Rectangle(52, 38, 61, 16));
this.setLayout(null);
textField1.setText("");
textField1.setBounds(new Rectangle(114, 35, 142, 22));
label2.setBounds(new Rectangle(52, 68, 61, 16));
label2.setText("学生姓名:");
textField2.setText("");
textField2.setBounds(new Rectangle(114, 65, 142, 22));
button1.setLabel("确定");
button1.setBounds(new Rectangle(84, 104, 71, 25));
button1.addActionListener(new IDFrame_button1_actionAdapter(this));
button2.setBounds(new Rectangle(166, 104, 71, 25));
button2.addActionListener(new IDFrame_button2_actionAdapter(this));
button2.setLabel("取消");
this.setResizable(false);
this.add(button2, null);
this.add(label1, null);
this.add(label2, null);
this.add(textField2, null);
this.add(textField1, null);
this.add(button1, null);
} void button1_actionPerformed(ActionEvent e) {
String id = textField1.getText();
String name = textField2.getText();
//这里得到id和name之后你可以放到数据库中,放入数据库的代码自己写,我先放到内存中了。
TestFrame.has.put(id, name);
this.dispose();
} void button2_actionPerformed(ActionEvent e) {
this.dispose();
}
} class IDFrame_button1_actionAdapter
implements java.awt.event.ActionListener {
IDFrame adaptee; IDFrame_button1_actionAdapter(IDFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
} class IDFrame_button2_actionAdapter
implements java.awt.event.ActionListener {
IDFrame adaptee; IDFrame_button2_actionAdapter(IDFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.button2_actionPerformed(e);
}
}
}class TestFrame_button1_actionAdapter
implements java.awt.event.ActionListener {
TestFrame adaptee; TestFrame_button1_actionAdapter(TestFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.button1_actionPerformed(e);
}
}class TestFrame_button2_actionAdapter
implements java.awt.event.ActionListener {
TestFrame adaptee; TestFrame_button2_actionAdapter(TestFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.button2_actionPerformed(e);
}
}class TestFrame_button3_actionAdapter
implements java.awt.event.ActionListener {
TestFrame adaptee; TestFrame_button3_actionAdapter(TestFrame adaptee) {
this.adaptee = adaptee;
} public void actionPerformed(ActionEvent e) {
adaptee.button3_actionPerformed(e);
}
}
然后编译运行就ok了。