Questa è un semplice jpanel con una jmenubar.
Ho una lista di Jcombobox e devo praticamente dopo aver cliccato "avvia" far partire uno dopo l'altro una serie di eseguibili.
A runtime ho diversi errori nati da quando ho iniziato a lavorare con gli eseguibili, il resto va tutto bene, credo sia una questione di gestione dell'eccezioni.....mi date una mano?
questo è il codice:
codice:
import java.io.*;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class NeuroStim extends JPanel implements ActionListener{
JButton avvia_test = null;
JMenuItem infoTest;
JMenuItem exitItem;
JMenuItem aboutItem;
JLabel nome_paziente;
JTextField nomePaziente;
JLabel test1;
JLabel test2;
JLabel test3;
JLabel test4;
JLabel test5;
JLabel test6;
JLabel test7;
JLabel test8;
JLabel test9;
JLabel test10;
JLabel test11;
JLabel test12;
JComboBox test01;
JComboBox test02;
JComboBox test03;
JComboBox test04;
JComboBox test05;
JComboBox test06;
JComboBox test07;
JComboBox test08;
JComboBox test09;
JComboBox test010;
JComboBox test011;
JComboBox test012;
String[] Lista_test;
ImageIcon a;
public NeuroStim(Container pane)
{
pane.setLayout(new GridLayout(30,3));
JMenuBar menubar = new JMenuBar();
JMenu menuStart, help;
menuStart = new JMenu(" File ");
menuStart.setMnemonic(KeyEvent.VK_H);
menubar.add(menuStart);
exitItem = new JMenuItem("Chiudi", KeyEvent.VK_X);
exitItem.addActionListener(this);
menuStart.add(exitItem);
help = new JMenu(" Help ");
help.setMnemonic(KeyEvent.VK_H);
menubar.add(help);
infoTest = new JMenuItem("Info test", KeyEvent.VK_H);
infoTest.addActionListener(this);
help.add(infoTest);
aboutItem = new JMenuItem("Info");
help.add(aboutItem);
aboutItem.addActionListener(this);
Lista_test = new String[13];
Lista_test[0]="BloccoAfacile";
Lista_test[1]="Blocco B facile";
Lista_test[2]="Blocco C facile";
Lista_test[3]="Blocco D facile";
Lista_test[4]="Blocco E facile";
Lista_test[5]="Blocco F facile";
Lista_test[6]="Blocco A medio";
Lista_test[7]="Blocco B medio";
Lista_test[8]="Blocco C medio";
Lista_test[9]="Blocco D medio";
Lista_test[10]="Blocco E medio";
Lista_test[11]="Blocco F medio";
Lista_test[12]="Blocco Fissazione";
test01= new JComboBox(Lista_test);
test01.addActionListener(this);
test02= new JComboBox(Lista_test);
test02.addActionListener(this);
test03= new JComboBox(Lista_test);
test03.addActionListener(this);
test04= new JComboBox(Lista_test);
test04.addActionListener(this);
test05= new JComboBox(Lista_test);
test05.addActionListener(this);
test06= new JComboBox(Lista_test);
test06.addActionListener(this);
test07= new JComboBox(Lista_test);
test07.addActionListener(this);
test08= new JComboBox(Lista_test);
test08.addActionListener(this);
test09= new JComboBox(Lista_test);
test09.addActionListener(this);
test010= new JComboBox(Lista_test);
test010.addActionListener(this);
test011= new JComboBox(Lista_test);
test011.addActionListener(this);
test012= new JComboBox(Lista_test);
test012.addActionListener(this);
nome_paziente = new JLabel("nome paziente: ");
test1=new JLabel ("blocco1:");
test2=new JLabel ("blocco2:");
test3=new JLabel ("blocco3:");
test4=new JLabel ("blocco4:");
test5=new JLabel ("blocco5:");
test6=new JLabel ("blocco6:");
test7=new JLabel ("blocco7:");
test8=new JLabel ("blocco8:");
test9=new JLabel ("blocco9:");
test10=new JLabel ("blocco10:");
test11=new JLabel ("blocco11:");
test12=new JLabel ("blocco12:");
nomePaziente= new JTextField();
pane.add(menubar, BorderLayout.NORTH);
pane.add(nome_paziente);
pane.add(nomePaziente);
pane.add(test1);
pane.add(test01);
pane.add(test2);
pane.add(test02);
pane.add(test3);
pane.add(test03);
pane.add(test4);
pane.add(test04);
pane.add(test5);
pane.add(test05);
pane.add(test6);
pane.add(test06);
pane.add(test7);
pane.add(test07);
pane.add(test8);
pane.add(test08);
pane.add(test9);
pane.add(test09);
pane.add(test10);
pane.add(test010);
pane.add(test11);
pane.add(test011);
pane.add(test12);
pane.add(test012);
ImageIcon mioLogo = new ImageIcon("C:/prova.gif");
JLabel miaLabel = new JLabel( mioLogo );
pane.add(miaLabel);
pane.validate();
avvia_test(pane);
}
private void avvia_test(Container container)
{
avvia_test = new JButton(" Avvia test ");
container.add(avvia_test);
avvia_test.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if(source==avvia_test)
{
if (nomePaziente.getText().length() == 0){
JOptionPane.showMessageDialog(null,
"Tutti i campi devono essere riempiti",
"Messaggio di errore",
JOptionPane.WARNING_MESSAGE);}
else { //il problema nasce da qui
{
String[] eseguibile= new String[13];
for (int i=0; i<13; i++){
if(test01.getSelectedItem()=="bloccoAfacile")
eseguibile[i]="c:/bloccoAfacile.exe";
}
for (int i=0; i<13; i++){
try {
Runtime.getRuntime().exec(eseguibile[i]);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Runtime.getRuntime().exec("c:/bloccoFissazione.exe");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
}
if (source == exitItem){
int ris;
ris=JOptionPane.showConfirmDialog(null,
"Sei sicuro di voler uscire?","Conferma uscita",
JOptionPane.YES_NO_OPTION);
if(ris==JOptionPane.YES_OPTION)
System.exit(1);
}
else if (source == aboutItem) {
JOptionPane.showMessageDialog(
NeuroStim.this,
"Test neuropsicologici ",
"tesi di laurea",
JOptionPane.PLAIN_MESSAGE);
}
else if (source == infoTest) {
JOptionPane.showMessageDialog(
NeuroStim.this,
"test numero 1\n" +
"test numero 2\n" +
"test numero 3\n" +
"test numero 4\n" +
"test numero 5\n" +
"test numero 6\n" ,
"test disponibili",
JOptionPane.PLAIN_MESSAGE);
}
}
private static void createAndShowGUI()
{
JFrame frame = new JFrame("NeuroStim");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
NeuroStim msm = new NeuroStim(frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}