packagetest_startPane;importjava.awt.Container;importjava.awt.Graphics;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.image.BufferedI...
package test_startPane;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class first {
public class endPanel extends JPanel{
BufferedImage background;
public endPanel() throws IOException {
background=ImageIO.read(getClass().getResource("白天.png"));
}
public void paint (Graphics g) {
g.drawImage(background,0,0,null);
}
public void revive() {
this.setVisible(true);
}
public void unrevive() {
this.setVisible(false);
}
}
public class startPanel extends JPanel{
BufferedImage background;
BufferedImage startImage;
JButton button1;
JButton button2;
public startPanel() throws IOException {
background=ImageIO.read(getClass().getResource("白天.png"));
startImage=ImageIO.read(getClass().getResource("上.png"));
setLayout(null);
button1=new JButton("单人");
button2=new JButton("双人");
/*ImageIcon icon = new ImageIcon("重来.png");
button1.setIcon(icon);
button2.setIcon(icon);*/
button1.setBounds(56,350,80,30);
button2.setBounds(248,350,80,30);
this.setVisible(true);
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
} catch (IOException e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
}
});
this.add(button1);
this.add(button2);
}
public void paint (Graphics g) {
g.drawImage(background,0,0,null);
g.drawImage(startImage,0,0,null);
}
}
public first() throws IOException {
JFrame jf=new JFrame("Flappybird_shh");
startPanel fp =new startPanel();
Container c=jf.getContentPane();
jf.setSize(384,448);
jf.setResizable(false);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
c.add(fp);
}
public static void main(String[] args) throws IOException {
new first();
}
}
在startPanel里打开endPanel 就监视事件不会写
展开