salve ragazzi, spero che possiate capire quello che sto per chiedervi, ma soprattutto che possiate aiutarmi.
ora vi spiego sto creando un programma dove selezionando una parola lui mi stampa un numero...
il codice seguente e questo :
String s[] = { " OPERAIO", " IMPIEGATO", " DIRIGENTE" } ;
JList list = new JList(s);
in pratica quando selezione per esempio "OPERAIO" lui stampa 1000.
il codice che ho usato per convertire è il seguente :
:muro: o=Integer.parseInt(list.getName()); dove logicamente mi da errore
il tutto avviene all'interno di un pulsante
sto usando eclipse
grazie di vero cuore per l'aiuto
Dovresti come minimo spiegare che logica c'è dietro alla generazione del numero da stampare
grazie per aver risposto, in che senso? ora ti mando tutto quello che ho fatto
questo e il main
public class main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
dipendenti d = new dipendenti();
}
}
mentre ora ti mando i
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.ArrayList;
import java.awt.Color;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JLabel;
import javax.swing.Action.*;
import javax.swing.*;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JList;
public class dipendenti extends JFrame{
JFrame Jf = new JFrame();
JPanel pa = new JPanel();
JLabel l1 = new JLabel();
JLabel l2 = new JLabel();
JLabel l3 = new JLabel();
JLabel l4 = new JLabel();
JLabel l5 = new JLabel();
JLabel l6 = new JLabel();
JLabel l7 = new JLabel();
JLabel l8 = new JLabel();
String s[] = { " OPERAIO", " IMPIEGATO", " DIRIGENTE" } ;
JList list = new JList(s);
String fig [] = { " SI ", " NO " } ;
JList lis = new JList(fig );
JTextField t1 = new JTextField ();
JTextField t2 = new JTextField ();
JTextField t3 = new JTextField ();
JTextField t4 = new JTextField ();
JTextField t5 = new JTextField ();
JTextField t6 = new JTextField ();
JButton puls = new JButton();
public dipendenti()
{
super ("STIPENDI DIPENDENTI");
super.setBackground(Color.green);
super.setBounds(850, 1, 500, 420);
super.setContentPane(pa);
pa.setBackground(Color.blue);
pa.setLayout(null);
l1.setText("Nome e Cognome ");
l1.setForeground(Color.white);
l1.setBounds(10, 10, 140, 20);
pa.add(l1);
l2.setText("QUALIFICA DEL DIPENDENTE");
l2.setForeground(Color.white);
l2.setBounds(10, 40, 160, 20);
pa.add(l2);
t1.setBackground(Color.yellow);
t1.setBounds(190, 10, 200, 20);
pa.add(t1);
list.setBackground(Color.YELLOW);
list.setBounds(190, 40, 250, 90);
pa.add(list);
l3.setText("SPOSATO");
l3.setForeground(Color.white);
l3.setBounds(10, 160, 140, 20);
pa.add(l3);
lis.setBackground(Color.yellow);
lis.setBounds(190, 150, 200, 35);
pa.add(lis);
l4.setText("QUANTI FIGLI ? ");
l4.setForeground(Color.white);
l4.setBounds(10, 190, 140, 20);
pa.add(l4);
t2.setBackground(Color.yellow);
t2.setBounds(190, 190, 200, 20);
pa.add(t2);
l5.setText("ORARIO DI LAVORO");
l5.setForeground(Color.white);
l5.setBounds(10, 220, 140, 20);
pa.add(l5);
t3.setBackground(Color.yellow);
t3.setBounds(190, 220, 200, 20);
pa.add(t3);
l6.setText("ORE DI STRAORDINARIO");
l6.setForeground(Color.white);
l6.setBounds(10, 250, 140, 20);
pa.add(l6);
t4.setBackground(Color.yellow);
t4.setBounds(190, 250, 200, 20);
pa.add(t4);
l7.setText("BONUS IN EURO ");
l7.setForeground(Color.white);
l7.setBounds(10, 280, 140, 20);
pa.add(l7);
t5.setBackground(Color.yellow);
t5.setBounds(190, 280, 200, 20);
pa.add(t5);
puls.setText("CALCOLA STIPENDIO ");
puls.setForeground(Color.BLUE);
puls.setBounds(190, 310, 200, 20);
pa.add(puls);
puls.setBackground(Color.yellow);
puls.addActionListener(new stipendio());
l8.setText(" POIIYU ");
l8.setForeground(Color.white);
l8.setBounds(200, 330, 140, 20);
pa.add(l8);
super.setVisible(true);
public class stipendio implements ActionListener
{
int i=1500; int o=1200; int D=4500;
public void actionPerformed(ActionEvent event)
{
int a=Integer.parseInt(t2.getText());
int b=Integer.parseInt(t3.getText());
int c=Integer.parseInt(t4.getText());
int d=Integer.parseInt(t5.getText());
:muro: o=Integer.parseInt(list.getName());
i=Integer.parseInt(list.getName());
D=Integer.parseInt(list.getName());
spero che capirai qualcosa
grazie lo stesso, finalmente ci sono riuscito era un semplice e cavolo di
"if" infatti quando ho provato a inserire le condizioni e partito tutto alla grande
buona giornata e grazie a tutti
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.