我使用以下代码在图像上显示一个 jbutton。但是直到我将光标放在按钮位置上,他的按钮才会显示。代码中的更正是什么?
文件Project31.java
package project31;
import javax.swing.JFrame;
import java.awt.*;
public class Project31 {
public static void main(String[] args) {
studentinfo studentinfo=new studentinfo();
studentinfo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
studentinfo.setSize(1368,768);
studentinfo.setVisible(true);
}
}
文件studentinfo.java
package project31;
import java.io.*;
import javax.sound.sampled.*;
import sun.audio.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class studentinfo extends JFrame{
private JButton plainJButton;
Image stuinfo=Toolkit.getDefaultToolkit().getImage("stuinfo.png");
public studentinfo(){
setLayout(new FlowLayout());
plainJButton=new JButton("Search");
add (plainJButton);
ButtonHandler handler=new ButtonHandler();
plainJButton.addActionListener(handler);
}
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent event){
}
}
public void paint(Graphics g){
g.drawImage(stuinfo,16,10,this);
}
}