jj.69kt
16-06-2008, 12:27
Avevo letto una cosa simile, ma non trovo il post....
Comunque.. Io ho un problema, un jpanel mi compare solo dopo che faccio il resize col mouse del JFrame..
ecco il codice:
package Progetto;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author Exol
*/
public class OptionPanel extends JPanel {
private JButton sparaButton;
private JTextField alzoTextField, speedTextField;
private JLabel alzoLabel, speedLabel;
private Float alzoFloat, speedFloat;
public OptionPanel(){
this.setLayout(new FlowLayout());
alzoLabel = new JLabel();
speedLabel = new JLabel();
sparaButton = new JButton();
alzoTextField = new JTextField();
speedTextField = new JTextField();
alzoLabel.setText("Alzo: ");
speedLabel.setText("Velocità: ");
sparaButton.setText("Spara");
alzoTextField.setText("00");
speedTextField.setText("00");
sparaButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
alzoFloat =new Float(alzoTextField.getText()).floatValue();
speedFloat =new Float(speedTextField.getText()).floatValue();
if ((e.getSource().equals(sparaButton))&& alzoFloat>0 && alzoFloat<=90 && speedFloat>0.1 && speedFloat<10.0)
{
//Begin Test
System.out.println("Alzo: " + alzoFloat);
System.out.println("Speed: " + speedFloat);
//End Test
//Azione dello sparo
//????????
}
else
JOptionPane.showMessageDialog(null, "Errore nell'input dei dati", "Errore", JOptionPane.ERROR_MESSAGE);
} catch(Exception exc) {
JOptionPane.showMessageDialog(null, "Errore tipologia dati", "Errore", JOptionPane.ERROR_MESSAGE);
}
}
});
this.add(alzoLabel);
this.add(alzoTextField);
this.add(speedLabel);
this.add(speedTextField);
this.add(sparaButton);
}
public static void main(String[]args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setBounds(10, 10, 700, 500);
frame.setLayout(new BorderLayout());
OptionPanel opt = new OptionPanel();
opt.setBounds(10, 10, 400, 100);
frame.add(opt);
opt.setVisible(true);
}
}
Immgino sia una cazzata.. Ma non riesco a trovare il sistema.. ;)
Comunque.. Io ho un problema, un jpanel mi compare solo dopo che faccio il resize col mouse del JFrame..
ecco il codice:
package Progetto;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
/**
*
* @author Exol
*/
public class OptionPanel extends JPanel {
private JButton sparaButton;
private JTextField alzoTextField, speedTextField;
private JLabel alzoLabel, speedLabel;
private Float alzoFloat, speedFloat;
public OptionPanel(){
this.setLayout(new FlowLayout());
alzoLabel = new JLabel();
speedLabel = new JLabel();
sparaButton = new JButton();
alzoTextField = new JTextField();
speedTextField = new JTextField();
alzoLabel.setText("Alzo: ");
speedLabel.setText("Velocità: ");
sparaButton.setText("Spara");
alzoTextField.setText("00");
speedTextField.setText("00");
sparaButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
try{
alzoFloat =new Float(alzoTextField.getText()).floatValue();
speedFloat =new Float(speedTextField.getText()).floatValue();
if ((e.getSource().equals(sparaButton))&& alzoFloat>0 && alzoFloat<=90 && speedFloat>0.1 && speedFloat<10.0)
{
//Begin Test
System.out.println("Alzo: " + alzoFloat);
System.out.println("Speed: " + speedFloat);
//End Test
//Azione dello sparo
//????????
}
else
JOptionPane.showMessageDialog(null, "Errore nell'input dei dati", "Errore", JOptionPane.ERROR_MESSAGE);
} catch(Exception exc) {
JOptionPane.showMessageDialog(null, "Errore tipologia dati", "Errore", JOptionPane.ERROR_MESSAGE);
}
}
});
this.add(alzoLabel);
this.add(alzoTextField);
this.add(speedLabel);
this.add(speedTextField);
this.add(sparaButton);
}
public static void main(String[]args){
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setBounds(10, 10, 700, 500);
frame.setLayout(new BorderLayout());
OptionPanel opt = new OptionPanel();
opt.setBounds(10, 10, 400, 100);
frame.add(opt);
opt.setVisible(true);
}
}
Immgino sia una cazzata.. Ma non riesco a trovare il sistema.. ;)