Ciao a tutti. Riscrivo sul forum perchè ho visto che la scorsa volta mi siete stati di grande aiuto..Ringrazio tutti in anticipo. Il problema è il seguente.
Devo passare dei dati inseriti in un form dall'utente ad un'altra classe che li utilizza per creare un altro frame con visualizzazione immagini.
La prima classe come detto poc'anzi è un frame che richiede all'utente di inserire dei valori (tra questi il numero di immagini da visualizzare). Dopo aver premuto il tasto 'OK' del frame la finestra si chiude e ne viene aperta un'altra con le immagini il cui numero è stato scelto dall'utente precedentemente. Nella prima classe la parte che richiama la seconda è queste..
Come definire il costruttore della classe schermo?codice:JButton btnNewButton_1 = new JButton("OK"); btnNewButton_1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String text1 = textField_1.getText(); String text2 = textField_2.getText(); String text3 = textField_3.getText(); String text4 = textField_4.getText(); String text5 = textField_5.getText(); //se uno dei campi è vuoto allora genera errore if (text1.equals("") || text2.equals("") || text3.equals("") || text4.equals("") || text5.equals("")) { String message = "Riempi tutti i campi\n" + "indicando il numero di secondi."; JOptionPane.showMessageDialog(new JFrame(), message, "Dialog", JOptionPane.ERROR_MESSAGE); //altrimenti uso numeri per costruire lo schermo per visualizzare immagini } else { int timeOfImage = Integer.parseInt(text1); int timeOfChoice = Integer.parseInt(text2); int numOfImages = Integer.parseInt(text3); int timeBeforeChoice = Integer.parseInt(text4); int timeBetwImage= Integer.parseInt(text5); dispose(); Schermo frame = new Schermo(timeOfImage, timeOfChoice, numOfImages, timeBeforeChoice, timeBetwImage); } } });
Ho pensato di fare cosi...
Ovviamente mi da errore nel main di tale classe quando crea..codice:public class Schermo extends JFrame { private JPanel contentPane; private static int image; private int choice; private int numImages; private int beforeChoice; private int betwImage; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Schermo frame = new Schermo(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } /** * Create the frame. * @param timeBetwImage * @param timeBeforeChoice * @param numOfImages * @param timeOfChoice * @param timeOfImage */ public Schermo(int image, int choice, int numImages, int beforeChoice, int betwImage) { this.image = image; this.choice = choice; this.numImages = numImages; this.beforeChoice = beforeChoice; this.betwImage = betwImage; setUndecorated(true); setForeground(Color.BLACK); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); contentPane = new JPanel(); contentPane.setBackground(Color.BLACK); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JPanel panel = new JPanel(); panel.setMaximumSize(new Dimension(32789, 32781)); panel.setBackground(Color.BLACK); contentPane.add(panel, BorderLayout.CENTER); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(0, 0, screenSize.width, screenSize.height); } }
dove qundi devo creare l'oggetto di tipo Schermo?Nella prima classe oppure nel main della classe schermo?codice:public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Schermo frame = new Schermo(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }

Rispondi quotando