这个java怎么修改才正确?
答案:1 悬赏:50 手机版
解决时间 2021-11-14 07:58
- 提问者网友:雪舞兮
- 2021-11-13 22:26
这个java怎么修改才正确?
最佳答案
- 五星知识达人网友:深街酒徒
- 2021-11-13 23:13
代码修改完可以运行,但可能有乱码问题,如果乱码去百度“awt中文乱码”
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Test {
static Frame f = new Frame("Welcome GUL");
static Label lb1 = new Label("欢迎进入Java的图形用户界面!");
static Label lb2 = new Label("在这里显示按钮事件描述");
static Button b1 = new Button("单击我");
static Button b2 = new Button("退出");
public static void main(String[] args) {
f.setSize(300, 200);
f.setLayout(new FlowLayout());
f.add(lb1);
f.add(lb2);
f.add(b1);
f.add(b2);
b1.addMouseListener(new Button1Handler());
b2.addActionListener(new Button2Handler());
f.setVisible(true);
}
}
class Button1Handler implements MouseListener {
public void mouseClicked(MouseEvent e) {
Test.lb2.setText("已进入按钮上方");
}
public void mouseEntered(MouseEvent e) {
Test.lb2.setText("已离开按钮上方");
}
public void mousePressed(MouseEvent e) {
Test.lb2.setText("已按下按钮");
}
public void mouseReleased(MouseEvent e) {
}
public void actionPerformed(ActionEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
class Button2Handler implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class Test {
static Frame f = new Frame("Welcome GUL");
static Label lb1 = new Label("欢迎进入Java的图形用户界面!");
static Label lb2 = new Label("在这里显示按钮事件描述");
static Button b1 = new Button("单击我");
static Button b2 = new Button("退出");
public static void main(String[] args) {
f.setSize(300, 200);
f.setLayout(new FlowLayout());
f.add(lb1);
f.add(lb2);
f.add(b1);
f.add(b2);
b1.addMouseListener(new Button1Handler());
b2.addActionListener(new Button2Handler());
f.setVisible(true);
}
}
class Button1Handler implements MouseListener {
public void mouseClicked(MouseEvent e) {
Test.lb2.setText("已进入按钮上方");
}
public void mouseEntered(MouseEvent e) {
Test.lb2.setText("已离开按钮上方");
}
public void mousePressed(MouseEvent e) {
Test.lb2.setText("已按下按钮");
}
public void mouseReleased(MouseEvent e) {
}
public void actionPerformed(ActionEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
class Button2Handler implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯