Problem with jar and windows

I created a program in java and i decided to make it executable on all platforms (obviously with the jvm). My idea was to create a jar file, I did it and I tested it on various platforms.

On linux (kubuntu 6.10 and slackware 10) it works very fine

On Mac Os X it works very fine

On Windows there is the problem: the file works, the program starts opening the first window and the window works fine. Then I press the "next" button but the second window doesn't start...better: a second window is launched but it has a white background, not the objects I put in it. I find out that enlarging and then resizing the window all the objects appear and the second window works normally (as in linux or os x). Where is the problem? How can i solve it?

[770 byte] By [Giammaa] at [2007-11-26 19:00:48]
# 1

> Where is the problem? How can i solve it?

How do you expect people on this forum to be able to answer this? They don't know anything about your program except that it does not work on Windows!

There are some people who seem to be able to read minds - you had better hope that one of them is available.

sabre150a at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 2
Ok. My program just takes a maximum of ten names and then makes a casual choice of the names. In the secon window the user must insert the names and then how many selections he wants to do: he can do this writing names and numbers in jtextfields. Do you need other infos?
Giammaa at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 3

Honestly: yes.

Like your code, or at least relevant parts of it, posted in [ code ] tags.

It doesn't really help when someone says "my application is failing to insert stuff into the database" and the reply to the question "what's it doing in detail?" is "it tries to store a shopping cart item". The expected reply would be "I try to load driver X and then grab a connection and execute a PreparedStatement like this: <code>"... :)

CeciNEstPasUnProgrammeura at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 4

even if my code works without problems, i insert it down

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class Finestradue extends JFrame {

//variabili globali

JPanel pannellouno=new JPanel();

JPanel pannellodue=new JPanel();

JPanel pannellotre=new JPanel();

JTextField camposcelta=new JTextField();

JTextField campoportatori=new JTextField();

JTextField nomeuno=new JTextField();

JTextField nomedue=new JTextField();

JTextField nometre=new JTextField();

JTextField nomequattro=new JTextField();

JTextField nomecinque=new JTextField();

JTextField nomesei=new JTextField();

JTextField nomesette=new JTextField();

JTextField nomeotto=new JTextField();

JTextField nomenove=new JTextField();

JTextField nomedieci=new JTextField();

//costruisco l'action listener per la prosecuzione

class proseguial implements ActionListener{

//variabili locali

int scelte;

int portatori;

String[] A;

//variabili locali di controllo dei passi

boolean passouno=false;

boolean passodue=false;

boolean passotre=true;

public void actionPerformed (ActionEvent e){

//eseguo il passo uno: controllo se i campi scelte e portatori non sono vuoti

if (camposcelta.getDocument().getLength()==0 || campoportatori.getDocument().getLength()==0){

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

}

else {

passouno=true;

try {

String s=camposcelta.getText();

scelte=Integer.valueOf(s).intValue();

String p=campoportatori.getText();

portatori=Integer.valueOf(p).intValue();

}

catch (Exception eccez){

passouno=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

}

}

//costruisco il passo due: vedo che portatori e scelte siano compatibili

if (passouno==true){

if (portatori<1 || scelte<1 || scelte>10 || portatori>=scelte) {

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

}

else{

passodue=true;

}

}

//costruisco il passo tre: costruisco l'array

if (passodue==true){

A=new String[scelte];

//inizializzo l'array a null

for (int i=0;i<scelte;i++)

A[i]=null;

//costruisco l'array

for (int i=0;i<scelte;i++){

if (i==0){

if (nomeuno.getDocument().getLength()==0){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomeuno.getText();

}

}

if (i==1){

if (nomedue.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomedue.getText();

}

}

if (i==2){

if (nometre.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nometre.getText();

}

}

if (i==3){

if (nomequattro.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomequattro.getText();

}

}

if (i==4){

if (nomecinque.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomecinque.getText();

}

}

if (i==5){

if (nomesei.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomesei.getText();

}

}

if (i==6){

if (nomesette.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomesette.getText();

}

}

if (i==7){

if (nomeotto.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomeotto.getText();

}

}

if (i==8){

if (nomenove.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomenove.getText();

}

}

if (i==9){

if (nomedieci.getDocument().getLength()==0 || passotre==false){

passotre=false;

setVisible(false);

Finestraerrore err=new Finestraerrore("Errore!");

break;

}

else {

A[i]=nomedieci.getText();

}

}

}

//se tutti i passi precedenti sono andati a buon fine lancio la finestra tre e le passo i parametri

if (passotre==true){

setVisible(false);

Finestratre tre=new Finestratre("Risultato",A,scelte, portatori);

}

}

}

}

//costruisco l'action listener per l'uscita

class escial implements ActionListener{

public void actionPerformed (ActionEvent e){

System.exit(-1);

}

}

public Finestradue (String s){

super (s);

//costruisco il pannellouno

JLabel etichettainiziale=new JLabel(" Inserire le informazioni richieste negli appositi spazi");

pannellouno.setLayout(new GridLayout(1,1));

pannellouno.setBackground(Color.orange);

pannellouno.add(etichettainiziale);

//costruisco il pannellodue

pannellodue.setLayout(new GridLayout(15,1));

pannellodue.setBackground(Color.orange);

JLabel etichettascelta=new JLabel("Inserire il numero di scelte fino ad un massimo di 10");

pannellodue.add(etichettascelta);

pannellodue.add(camposcelta);

JLabel etichettaportatori=new JLabel("Inserire il numero di portatori che verranno inviati");

pannellodue.add(etichettaportatori);

pannellodue.add(campoportatori);

JLabel etichettanomi=new JLabel ("Inserire i nomi delle possibili scelte");

pannellodue.add(etichettanomi);

pannellodue.add(nomeuno);

pannellodue.add(nomedue);

pannellodue.add(nometre);

pannellodue.add(nomequattro);

pannellodue.add(nomecinque);

pannellodue.add(nomesei);

pannellodue.add(nomesette);

pannellodue.add(nomeotto);

pannellodue.add(nomenove);

pannellodue.add(nomedieci);

//costruisco il pannellotre

pannellotre.setLayout(new GridLayout(1,2));

JButton prosegui=new JButton("Prosegui");

prosegui.addActionListener(new proseguial());

JButton esci=new JButton("Esci");

esci.addActionListener(new escial());

pannellotre.add(prosegui);

pannellotre.add(esci);

//costruisco la finestra

getContentPane().setBackground(Color.orange);

getContentPane().add(pannellouno,BorderLayout.NORTH);

getContentPane().add(pannellodue,BorderLayout.CENTER);

getContentPane().add(pannellotre,BorderLayout.SOUTH);

setVisible(true);

setSize(500,400);

setDefaultCloseOperation(EXIT_ON_CLOSE);

}

}

>

Giammaa at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 5
> even if my code works without problems,Let's see.By the way, did you know about switch statements? You badly need one. Or rather an array of text fields, on second glance.
CeciNEstPasUnProgrammeura at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 6
sincerly i didn't think to those ideas. Thanks for the idea :D
Giammaa at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 7
But that doesn't help with your problem. Which of the things is the "next" button and its listener code?
CeciNEstPasUnProgrammeura at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 8

I think you got a problem with displaying the UI before resizing it at

getContentPane().add(pannellotre, BorderLayout.SOUTH);

setVisible(true);

setSize(500, 400);

setDefaultCloseOperation(EXIT_ON_CLOSE);

That code will work if you refresh the page again, otherwise you will get problem like blank page.

try to put

setVisible(true);

at the end of the constructor.

ot6a at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 9
Try and pack() the frame prior to setting it visible.#
duckbilla at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 10
"Next" button is prosegui and its action listener is proseguial
Giammaa at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...
# 11
i solved my problem installing JRE 6... :(
Giammaa at 2007-7-9 20:43:33 > top of Java-index,Java Essentials,New To Java...