JAVA 关于图形界面编程中的初级问题
来源:百度知道 编辑:UC知道 时间:2024/08/22 01:27:49
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class work1103
{
public static void main(String[] s){
guiClass t= new guiClass();
t.show();
}
}
class guiClass
{
JFrame f;
JButton btn;
void show()
{
JFrame f = new JFrame("Demo Frame");
JButton btn = new JButton("你好!");
btn.addActionListener(new test(this));
f.getContentPane().add(btn);
f.setLocation(100, 300);
f.setSize(300,300);
f.setVisible(true);
}
}
class test implements ActionListener
{
guiClass gui;
test(guiClass gui){this.gui=gui;}
public void actionPerformed(ActionEvent e) {
try{
if (gui.btn.getText().equals("早安!"))
gui.btn.setText("你好!");
import java.awt.event.*;
import javax.swing.*;
public class work1103
{
public static void main(String[] s){
guiClass t= new guiClass();
t.show();
}
}
class guiClass
{
JFrame f;
JButton btn;
void show()
{
JFrame f = new JFrame("Demo Frame");
JButton btn = new JButton("你好!");
btn.addActionListener(new test(this));
f.getContentPane().add(btn);
f.setLocation(100, 300);
f.setSize(300,300);
f.setVisible(true);
}
}
class test implements ActionListener
{
guiClass gui;
test(guiClass gui){this.gui=gui;}
public void actionPerformed(ActionEvent e) {
try{
if (gui.btn.getText().equals("早安!"))
gui.btn.setText("你好!");
//经测试,程序没错误
//你的代码是弹出报错对话框
//我改完的代码是按钮上文字改变
import javax.swing.*;
import java.awt.event.*;
import javax.swing.JOptionPane;
public class work1103 {
public static void main(String[] s) {
guiClass t = new guiClass();
t.show();
}
}
class guiClass {
JFrame f;
JButton btn;
void show() {
f = new JFrame("Demo Frame");
btn = new JButton("你好!");
btn.addActionListener(new test(this));
f.getContentPane().add(btn);
f.setLocation(100, 300);
f.setSize(300, 300);
f.setVisible(true);
}
}
class test implements ActionListener {
private guiClass gui;
test(guiClass gui){
this.gui=gui;
}
public void actionPerformed(ActionEvent e) {
try {
if (gui.btn.getText().equals("早安!"))
gui.btn.setText("你好!");
else
gu