0
回答
setVisible(false);无法关闭界面
科大讯飞通用文字识别100000次/天免费使用。立即申请   
import java.awt.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.event.*;


public class quickGame {
	
	public void lanch(){
		JFrame frm=new JFrame();
		frm.setBounds(320,60,50,600);
		
	}

	public quickGame(){
		JFrame frame = new JFrame();
		//设置主画框的位置和大小
		frame.setBounds(320,60,500,600);
		Container c=frame.getContentPane();
		frame.setSize(500,600);
		
		
		
			
		c.setLayout(new BorderLayout());
		
		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new FlowLayout());
		ImageIcon img = new ImageIcon(this.getClass().getResource("quickgame.png"));
		titlePanel.add(new JLabel(img));
		c.add(titlePanel,"North");
		
		JPanel fieldPanel = new JPanel();
		fieldPanel.setLayout(null);
		ImageIcon img1 = new ImageIcon(this.getClass().getResource("罐子.png"));
		JLabel l1 = new JLabel(img1);
		l1.setBounds(20, 0, 280, 380);
		fieldPanel.add(l1);
		c.add(fieldPanel,"Center");
		
		
		JPanel buttonPanel = new JPanel();
		ImageIcon img2 = new ImageIcon(this.getClass().getResource("bt_start_3.png"));
		SimpleListener listener=new SimpleListener();
		JButton b1= new JButton("",img2);
		buttonPanel.add(b1);
		b1.setBounds(30,20,120,70);
		b1.setActionCommand("1");
		b1.addActionListener(listener);
		
		c.add(buttonPanel,BorderLayout.EAST);
		JPanel buttonPanel1 = new JPanel();
		
		JButton b= new JButton("返回");
		buttonPanel1.add(b);
		b.setBounds(0,0,0,0);
		b.setActionCommand("5");
		b.addActionListener(listener);
		
		c.add(buttonPanel1,BorderLayout.WEST);
		frame.setVisible(true);
		frame.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent e){System.exit(0);
			}});
	}

	public  class SimpleListener implements java.awt.event.ActionListener{
	    public void actionPerformed(java.awt.event.ActionListener evt) { 
			  
			  }

		
		
		
		public void actionPerformed(ActionEvent e) {
		
			String command=((ActionEvent) e).getActionCommand();
		     if(command.equals("1")){
		    	 new waterspray();
		    	 setVisible(false);
		    	 
		     }
		     else if(command.equals("5")){
		    	 System.exit(0);
		     }
		}

		
	}
		
	public static void main(String[] args) {
		
		new quickGame();
	}





	
	
}

如图  我应该怎么修改才能  隐藏这个界面  进入new waterspray();的界面  现在能进入 就是隐藏不了  
举报
L3ve
发帖于7年前 0回/1K+阅
顶部