当我单击按钮时,我试图在 a 上绘制图像JPanel
,但我对paintComponent
和感到困惑mouselistener
。
这是我到目前为止所做的代码。
public class Efi {
public JFrame frame;
public JButton button;
private JPanel panel;
private JPanel panel1 = new JPanel(new FlowLayout());
private JPanel panel2 = new JPanel(new FlowLayout());
private Image sex = new ImageIcon("img.jpg").getImage();
public Efi() {
frame = new JFrame("EFI'S APPLICATION");
frame.setLayout(null);
button = new JButton("IMAGE");
button.setLocation(0, 0);
button.setSize(500, 50);
frame.add(button);
button.addMouseListener(ML);
panel = new JPanel(null);
panel.setSize(400, 400);
panel.setLocation(50, 50);
panel.setVisible(true);
panel.setLayout(null);
panel.setBorder(BorderFactory.createLineBorder(Color.black, 2));
frame.add(panel);
}
// super.paintComponent(g);
MouseListener ML = new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
};
}