DnA[TF]
29-12-2005, 15:21
Devo fare un altro programma per scuola.. non ho capito una cosa però..
Io sto lavorando con la GUI .. quindi sto creando un'interfaccia grafica..
vi posto il codice con l'errore..
//Dna
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Credito extends JFrame implements ActionListener
{
//creo 5 pannelli
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JPanel p5 = new JPanel();
//creo 3 JTextField
JTextField media = new JTextField(10);
JTextField debiti = new JTextField(10);
JTextField crediti = new JTextField(10);
//creo 3 pulsanti
JButton calcola = new JButton("Calcola credito");
JButton annulla = new JButton("Annulla");
JButton cambiaColore = new JButton("Cambio colore testo label");
//crea una combobox
JComboBox sceltaColor = new JComboBox();
//Creo 4 etichette non modificabili
JLabel l1 = new JLabel("Media voti");
JLabel l2 = new JLabel("Numero debiti");
JLabel l3 = new JLabel("Punti di credito");
JLabel l4 = new JLabel("Colore testo Label");
public Credito(String titolo)
{
super(titolo);
setBounds(50,50,500,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(Color.WHITE);
p1.setBackground(Color.BLACK);
p2.setBackground(Color.BLACK);
p3.setBackground(Color.BLACK);
p4.setBackground(Color.BLACK);
p5.setBackground(Color.BLACK);
calcola.setBackground(Color.WHITE);
calcola.setForeground(Color.BLACK);
annulla.setBackground(Color.WHITE);
annulla.setForeground(Color.BLACK);
cambiaColore.setBackground(Color.WHITE);
cambiaColore.setForeground(Color.BLACK);
l1.setForeground(Color.GREEN);
l2.setForeground(Color.GREEN);
l3.setForeground(Color.GREEN);
l4.setForeground(Color.GREEN);
sceltaColor.addItem("Rosso");
sceltaColor.addItem("Blu");
sceltaColor.addItem("Giallo");
sceltaColor.addItem("Verde");
getContentPane().setLayout(new GridLayout(5,1));
p1.add(l1);
p1.add(media);
p2.add(l2);
p2.add(debiti);
p3.add(calcola);
p3.add(annulla);
p4.add(l3);
p4.add(crediti);
p5.add(l4);
p5.add(sceltaColor);
p5.add(cambiaColore);
getContentPane().add(p1);
getContentPane().add(p2);
getContentPane().add(p3);
getContentPane().add(p4);
getContentPane().add(p5);
calcola.addActionListener(this);
annulla.addActionListener(this);
cambiaColore.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
JButton source =(JButton) e.getSource();
int A,B;
if(source == annulla)
{
media.setText("");
debiti.setText("");
crediti.setText("");
}
if(source == calcola)
{
if(A<6)
{
crediti.setText("0");
}
if((A=6)&&(B=0))
{
crediti.setText("2");
}
}
}
public static void main(String args[])
{
Credito c = new Credito("Calcola Credito");
}
}
devo:
calcolare i punti di credito in base alla tabella
Media voti
M<6 punti credito 0
M=6 2-3 punti
6<M<=7 3-4 punti
7<M<=8 4-5 punti
M>8 5-6 pnt
In più se c'è un debito devo prendere il valore piu basso della fascia .. tipo se ho la media >8 e ho un debito prendo 5 punti.. e non 6..
Ok il mio problema sta nel fare gli If... non mi lascia fare
if((A=6)&&(B=0)) perchè mi da l'errore che && non si usa ai tipi int e double.. bho aiutatemi
Io sto lavorando con la GUI .. quindi sto creando un'interfaccia grafica..
vi posto il codice con l'errore..
//Dna
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Credito extends JFrame implements ActionListener
{
//creo 5 pannelli
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
JPanel p3 = new JPanel();
JPanel p4 = new JPanel();
JPanel p5 = new JPanel();
//creo 3 JTextField
JTextField media = new JTextField(10);
JTextField debiti = new JTextField(10);
JTextField crediti = new JTextField(10);
//creo 3 pulsanti
JButton calcola = new JButton("Calcola credito");
JButton annulla = new JButton("Annulla");
JButton cambiaColore = new JButton("Cambio colore testo label");
//crea una combobox
JComboBox sceltaColor = new JComboBox();
//Creo 4 etichette non modificabili
JLabel l1 = new JLabel("Media voti");
JLabel l2 = new JLabel("Numero debiti");
JLabel l3 = new JLabel("Punti di credito");
JLabel l4 = new JLabel("Colore testo Label");
public Credito(String titolo)
{
super(titolo);
setBounds(50,50,500,400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().setBackground(Color.WHITE);
p1.setBackground(Color.BLACK);
p2.setBackground(Color.BLACK);
p3.setBackground(Color.BLACK);
p4.setBackground(Color.BLACK);
p5.setBackground(Color.BLACK);
calcola.setBackground(Color.WHITE);
calcola.setForeground(Color.BLACK);
annulla.setBackground(Color.WHITE);
annulla.setForeground(Color.BLACK);
cambiaColore.setBackground(Color.WHITE);
cambiaColore.setForeground(Color.BLACK);
l1.setForeground(Color.GREEN);
l2.setForeground(Color.GREEN);
l3.setForeground(Color.GREEN);
l4.setForeground(Color.GREEN);
sceltaColor.addItem("Rosso");
sceltaColor.addItem("Blu");
sceltaColor.addItem("Giallo");
sceltaColor.addItem("Verde");
getContentPane().setLayout(new GridLayout(5,1));
p1.add(l1);
p1.add(media);
p2.add(l2);
p2.add(debiti);
p3.add(calcola);
p3.add(annulla);
p4.add(l3);
p4.add(crediti);
p5.add(l4);
p5.add(sceltaColor);
p5.add(cambiaColore);
getContentPane().add(p1);
getContentPane().add(p2);
getContentPane().add(p3);
getContentPane().add(p4);
getContentPane().add(p5);
calcola.addActionListener(this);
annulla.addActionListener(this);
cambiaColore.addActionListener(this);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
JButton source =(JButton) e.getSource();
int A,B;
if(source == annulla)
{
media.setText("");
debiti.setText("");
crediti.setText("");
}
if(source == calcola)
{
if(A<6)
{
crediti.setText("0");
}
if((A=6)&&(B=0))
{
crediti.setText("2");
}
}
}
public static void main(String args[])
{
Credito c = new Credito("Calcola Credito");
}
}
devo:
calcolare i punti di credito in base alla tabella
Media voti
M<6 punti credito 0
M=6 2-3 punti
6<M<=7 3-4 punti
7<M<=8 4-5 punti
M>8 5-6 pnt
In più se c'è un debito devo prendere il valore piu basso della fascia .. tipo se ho la media >8 e ho un debito prendo 5 punti.. e non 6..
Ok il mio problema sta nel fare gli If... non mi lascia fare
if((A=6)&&(B=0)) perchè mi da l'errore che && non si usa ai tipi int e double.. bho aiutatemi