java Swing 按钮不显示、鼠标滑过才显示
import javax.swing.*;import java.awt.*;
import java.awt.event.*;
import java.awt.image.ImageObserver;
public class Welcome extends JFrame{
/**
*
*/
private static final long serialVersionUID = 1L;
/**
*
*/
private JButton JB,JB1,JB2,JB3;
private JLabel JL;
private Image img;
private Toolkit tool;
Welcome(){
super("欢迎来到科帮网");
setSize(600,500);
setLocation(250, 150);
Container container = getContentPane();
tool = getToolkit();
container.setLayout(null);
JB = new JButton("查询学校景点信息");
JB1 = new JButton("查询2景点间的最短距离");
JB2 = new JButton("查询旅游路线");
JB3 = new JButton("退出");
JL = new JLabel("欢迎使用校园导游咨询系统");
img = tool.getImage("E://School.jpg");
JB.addActionListener(new MyMonitor());
JB1.addActionListener(new MyMonitor());
JB2.addActionListener(new MyMonitor());
JB3.addActionListener((new MyMonitor()));
JL.setBounds(180, 20, 300, 40);
JB.setBounds(200, 60, 200, 30);
JB1.setBounds(200, 100, 200, 30);
JB2.setBounds(200, 140,200, 30);
JB3.setBounds(500, 400, 90, 30);
container.add(JB);
container.add(JB1);
container.add(JB2);
container.add(JB3);
container.add(JL);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private class MyMonitor implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(e.getSource()==JB){
new MyGraphy();
setVisible(false);
}
if(e.getSource()==JB1){
new ShowLength();
setVisible(false);
}
if(e.getSource()==JB2){
new ShowView();
setVisible(false);
}
if(e.getSource()==JB3){
System.exit(0);
}
}
}
public void paint(Graphics g){
g.drawImage(img, 100, 230, 400, 250, (ImageObserver) this);
}
public static void main(String[] args) {
new Welcome();
}
}
原因:paint方法被你重写了,但是你没处理好、所以要在 paint 方法前加super.paint(g)
下来,学习一下。谢谢:victory: 这个项目太棒勒!下下来学习下! 不错不错不错不错 不错不错不错
页:
[1]