2016-04-06 14 views
2

java'da bir program yapıyorum ve düğmeyi tıklattığımda yeni pencereden geçmek istiyorum ancak programı çalıştırdığımda 2 görüntülemeyi otomatik olarak açsam da Bu sorunu gidermek için ne yapabilirim?sfml 'deki baskı blokları

Ana:

package com.SimplyGeometry.src.tiles; 

import com.SimplyGeometry.src.windows.SelectWindow; 
import com.SimplyGeometry.src.windows.StartWindow; 

public class Main { 

    public static void main(String[] args) { 
     String title = "SimplyGeometry"; 
     int WIDTH = 1320, HEIGHT = 840; 
     StartWindow stw = new StartWindow(/*WIDTH, HEIGHT, title*/); 
    } 

} 

Vew1:

package com.SimplyGeometry.src.windows; 


import javax.swing.*; 

import Actions.Actions; 


public class StartWindow implements ActionListener { 

    public static JFrame window; 
    SelectWindow sw; 

    public StartWindow(/*int WIDTH, int HEIGHT, String title*/) { 

     window = new JFrame("SimplyGeometry"); 
     window.setPreferredSize(new Dimension(1320, 840)); 
     window.setMaximumSize(new Dimension(1320, 840)); 
     window.setMinimumSize(new Dimension(1320, 840)); 
     window.setLocationRelativeTo(null); 
     window.setResizable(false); 

     JPanel panel = new JPanel(); 
     panel.setLayout(null); 
     panel.setBounds(0, 0, 1320, 840); 
     panel.setBackground(Color.CYAN); 

     JLabel label = new JLabel(); 
     label.setIcon(new ImageIcon("/Users/gaetanodonnarumma/Documents/workspace/SimplyGeometry(Complete)/src/Images/titolo.png")); 
     label.setSize(650, 250); 
     label.setLocation(320, 100); 

     JButton button = new JButton("Start"); 
     button.setBackground(Color.white); 
     button.setForeground(Color.black); 
     button.setSize(350, 100); 
     button.setLocation(455, 450); 
     button.setEnabled(true); 
     button.addActionListener(new Actions()); 

     window.add(panel); 
     panel.add(label); 
     window.validate(); 
     panel.add(button); 

     window.setVisible(true); 
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    } 

    @Override 
    public void actionPerformed(ActionEvent e) { 
     // TODO Auto-generated method stub 

    } 
} 

Görünüm 2:

package com.SimplyGeometry.src.windows; 

import java.awt.Dimension; 

import javax.swing.*; 

public class SelectWindow { 

    public static JFrame window; 

    public SelectWindow(/*int WIDTH, int HEIGHT, String title*/) { 
     window = new JFrame("SimplyGeometry"); 
     window.setPreferredSize(new Dimension(1320, 840)); 
     window.setMaximumSize(new Dimension(1320, 840)); 
     window.setMinimumSize(new Dimension(1320, 840)); 
     window.setLocationRelativeTo(null); 
     window.setLayout(null); 

     window.setVisible(true); 
     window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    } 

} 

ActionListener sınıfı:

package Actions; 

import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 

import com.SimplyGeometry.src.windows.SelectWindow; 
import com.SimplyGeometry.src.windows.StartWindow; 

public class Actions implements ActionListener { 

    public Actions() { 
     SelectWindow window = new SelectWindow(); 
    } 

    @Override 
    public void actionPerformed(ActionEvent e) { 
     // TODO Auto-generated method stub 

    } 

} 

cevap

2

Çünkü aşağıda hattın oluyor: Actions yapıcısı olarak

public StartWindow(
    ... 
    button.addActionListener(new Actions()); 
    ... 
} 

, SelectWindow yaratıyor. Yani, StartWindow'u oluşturduktan sonra ekrana geliyor.

public Actions() { 
    SelectWindow window = new SelectWindow(); 
} 

sorun actionPerformed yılında SelectWindow oluşturmak çözmek için.

public class Actions implements ActionListener { 

    public Actions() { 
     //SelectWindow window = new SelectWindow(); 
    } 

    @Override 
    public void actionPerformed(ActionEvent e) { 
     SelectWindow window = new SelectWindow(); 
    } 

} 
+0

Çok teşekkür ederim – GADO