求JAVA大神如何点击一个按钮打开另一个Panel 10
packagetest_startPane;importjava.awt.Container;importjava.awt.Graphics;importjava.awt...
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 就监视事件不会写 展开
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 就监视事件不会写 展开
1个回答
2018-05-06 · 知道合伙人互联网行家
关注
展开全部
import java.awt.*;
import java.awt.event.*;import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class button extends JFrame{
public button(){
JButton button=new JButton("查找");
setLayout(new FlowLayout());
add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
selectinterface sl = new selectinterface();
sl.setVisible(true);
sl.pack();
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
button frame=new button();
frame.setTitle("按钮");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,600);
frame.setVisible(true);
}
}
class selectinterface extends JFrame{
public selectinterface(){
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(9,2,5,5));
p1.add(new JLabel("编号"));
p1.add(new JTextField(6));
p1.add(new JLabel("姓名"));
p1.add(new JTextField(8));
p1.add(new JLabel("性别"));
p1.add(new JTextField(1));
p1.add(new JLabel("年龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("职位"));
p1.add(new JTextField(20));
p1.add(new JLabel("学历"));
p1.add(new JTextField(4));
p1.add(new JLabel("学位"));
p1.add(new JTextField(4));
p1.add(new JLabel("工龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("工资等级"));
p1.add(new JTextField(2));
JPanel p2=new JPanel();
p2.add(new JButton("确定"));
p2.add(new JButton("取消"));
setLayout(new GridLayout(2,1,0,100));
add(p1);
add(p2);
}
}
import java.awt.event.*;import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class button extends JFrame{
public button(){
JButton button=new JButton("查找");
setLayout(new FlowLayout());
add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
selectinterface sl = new selectinterface();
sl.setVisible(true);
sl.pack();
}
});
}
public static void main(String[] args) {
// TODO Auto-generated method stub
button frame=new button();
frame.setTitle("按钮");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400,600);
frame.setVisible(true);
}
}
class selectinterface extends JFrame{
public selectinterface(){
JPanel p1=new JPanel();
p1.setLayout(new GridLayout(9,2,5,5));
p1.add(new JLabel("编号"));
p1.add(new JTextField(6));
p1.add(new JLabel("姓名"));
p1.add(new JTextField(8));
p1.add(new JLabel("性别"));
p1.add(new JTextField(1));
p1.add(new JLabel("年龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("职位"));
p1.add(new JTextField(20));
p1.add(new JLabel("学历"));
p1.add(new JTextField(4));
p1.add(new JLabel("学位"));
p1.add(new JTextField(4));
p1.add(new JLabel("工龄"));
p1.add(new JTextField(2));
p1.add(new JLabel("工资等级"));
p1.add(new JTextField(2));
JPanel p2=new JPanel();
p2.add(new JButton("确定"));
p2.add(new JButton("取消"));
setLayout(new GridLayout(2,1,0,100));
add(p1);
add(p2);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询