0

what can i do for call a private constructor from another file to open a window?

the class juego inside los señore package Los_señore; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Dimension; import javax.swing.JFrame; public class Juego extends Canvas{ private static final long serialVersionUID = 1L; private static final int ANCHO = 1000; private static final int ALTO = 800; private static final String NOMBRE = "Juego"; private static JFrame ventana; public Juego(){ setPreferredSize(new Dimension(ANCHO, ALTO)); ventana = new JFrame(NOMBRE); ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ventana.setResizable(false); ventana.setLayout(new BorderLayout()); ventana.add(this, BorderLayout.CENTER); ventana.pack(); ventana.setLocationRelativeTo(null); ventana.setVisible(true); } } the other class that iclude main import Los_señore.Juego; class prueba{ public static void main(String[] args){ Juego pepe = new Juego(); pepe.Juego(); } }

25th Feb 2017, 3:01 PM
Ismael Perbech
Ismael Perbech - avatar
1 Antwort
+ 4
Constructors can never be private (except you don't want it to be called from outside -> Singleton). Always public.
25th Feb 2017, 3:26 PM
Tashi N
Tashi N - avatar