java菜鸟,望大侠相助!!!

来源:百度知道 编辑:UC知道 时间:2024/06/30 13:41:40
2、将下面的部分程序补充完整,并运行该程序。
当敲击不同的按钮,文本框中将显示不同的内容。运行该程序,体会事件的监听和处理过程。

import java. awt. *;
import java. awt.event. *;
import javax.swing. *;
public class ActionDemo
extends JFrame{
JPanel contentPane;
BorderLayout borderLayout1=new BorderLayout();
JButton jButton1=new JButton("中文");
JButton jButton2=new JButton("英文");
JTextField text=new JTextField(10);

//Construct the frame
public ActionDemo(String title){
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
this.setTitle(title);
try{
jbInit();
}
catch(Exception e){
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception{
contentPane=(JPanel)this.getContentPane();
contentPane.setLayout(borderLayout1);
contentPane.add(jButton1,BorderLayout.EAST);
contentPane.add(jButton2,BorderLayout.WEST);
contentPane.ad

我把你的程序添加了几行代码,添加后的程序如下,你看下行不?

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
public class ActionDemo
extends JFrame{
JPanel contentPane;
BorderLayout borderLayout1=new BorderLayout();
JButton jButton1=new JButton("中文");
JButton jButton2=new JButton("英文");
JTextField text=new JTextField(10);

//Construct the frame
public ActionDemo(String title){
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
this.setTitle(title);
try{
jbInit();
}
catch(Exception e){
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception{
contentPane=(JPanel)this.getContentPane();
contentPane.setLayout(borderLayout1);
contentPane.add(jButton1,BorderLayout.EAST);
contentPane.add(jButton2,BorderLayout.WEST);
contentPane.add(text,BorderLayout.NORTH);
JButton1_action