| |
Živjo, napisal sem program v javi v katerem označuješ JRadioButtne, ko pa klikneš gumb izračunaj , ti program v novem oknu izpiše "Vsota je..." + total.
Vse lepo in prav, ampak ko uporabnik zapre to okno in npr. spremeni en gumb(ali pa tudi ne) in kilkne izračunaj program vrne vsoto prejšnjih gumbov + vsoto sedaj izbranih gumbov.
Kako bi naredil gumb reset, ali pa še bolje neko textovno polje v katerem se vsota prikazuje sproti. Npr. ko označiš en gumb se doda 10, če potem označiš drugega (vrednost 25) in da izpiše vrednost 25 ne pa 35... Prosim za pomoč...
spremenil: NikMan (9.8.2010 ob 14.02.59)
|
| |
| |
V splošnem pa bi morali biti nekako tako.
Za gumb Reset samo dodaš, da se s klikom na ta gumb vrednost spremenljivke, v katero se shranjuje vsota, nastavi na 0.
Za sprotno izpisovanje pa je potrebno uporabiti event oz. dogodek na JRadioButton in ko se ta dogodek zgodi, posodobiš vsoto ter jo izpišeš.
Fino bi bilo, če bi lahko prilepil kodo, kako imaš sedaj to narejeno, saj se le tako lahko poda bolj točen odogovor.
|
| |
| |
Toje je koda.... import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class tuna extends JFrame implements ActionListener
{
double total = 0.0;
JRadioButton b1,b2,b3 ,b4, b5 ,b6, b7, b8 ,b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19, b20, b21, b22, b23, b24;
JLabel l1;
JLabel l2, l3,l4,l5,l6,l7;
JButton button;
ButtonGroup g1, g2, g3, g4, g5, g6, g7;
public tuna(){
setLayout(null);
l1 = new JLabel();
b1 = new JRadioButton();
b2 = new JRadioButton();
l2 = new JLabel();
b3 = new JRadioButton();
b4 = new JRadioButton();
l3 = new JLabel();
b5 = new JRadioButton();
b6 = new JRadioButton();
b7 = new JRadioButton();
b8 = new JRadioButton();
b9 = new JRadioButton();
l4 = new JLabel();
b10 = new JRadioButton();
b11 = new JRadioButton();
l5 = new JLabel();
b12 = new JRadioButton();
b13 = new JRadioButton();
b14 = new JRadioButton();
l6 = new JLabel();
b15 = new JRadioButton();
b16 = new JRadioButton();
b17 = new JRadioButton();
b18 = new JRadioButton();
b19 = new JRadioButton();
b20 = new JRadioButton();
b21 = new JRadioButton();
b22 = new JRadioButton();
l7 = new JLabel();
b23 = new JRadioButton();
b24 = new JRadioButton();
button = new JButton();
l1.setLocation(10,2);
b1.setLocation(10,20);
b2.setLocation(10,40);
l2.setLocation(10,70);
b3.setLocation(10,90);
b4.setLocation(10,110);
l3.setLocation(10, 140);
b5.setLocation(10,160);
b6.setLocation(10,180);
b7.setLocation(10,200);
b8.setLocation(10,220);
b9.setLocation(10,240);
l4.setLocation(10,270);
b10.setLocation(10,290);
b11.setLocation(10,310);
l5.setLocation(10,340);
b12.setLocation(10,360);
b13.setLocation(10,380);
b14.setLocation(10,400);
l6.setLocation(10,430);
b15.setLocation(10,450);
b16.setLocation(10,470);
b17.setLocation(10,490);
b18.setLocation(10,510);
b19.setLocation(10,530);
b20.setLocation(10,550);
b21.setLocation(10,570);
b22.setLocation(10,590);
l7.setLocation(10, 620);
b23.setLocation(10,640);
b24.setLocation(10,660);
button.setLocation(100, 700);
l1.setText("Sem: ");
b1.setText("Dijak");
b2.setText("Študent");
l2.setText("Izobražujem se: ");
b3.setText("V Sloveniji");
b4.setText("V tujini");
l3.setText("Dohodek na družinskega člana v % minimalne plače: ");
b5.setText("Do vključno 25% ");
b6.setText("Nad 25% do vključno 40% ");
b7.setText("Nad 40% do vključno 50% ");
b8.setText("Nad 50% do vključno 60%");
b9.setText("Nad 60% ");
l4.setText("Dobil bom/Dobivam dodatek na področje izobraževanja: ");
b10.setText("Da");
b11.setText("Ne");
l5.setText("Imam povprečno oceno: ");
b12.setText("Več kot 4.1/8.5 in manj kot 4.5/9.0 ");
b13.setText("Nad 4.5/9.0 ");
b14.setText("Pod 4.1/8.5");
l6.setText("V šolo se vozim/bivam... ");
b15.setText("Bivam v dijaškem/študentskem domu ");
b16.setText("Se vozim 5 do vključno 10km ");
b17.setText("Se vozim nad 10 do vključno 15km ");
b18.setText("Se vozim nad 15 do vključno 20km ");
b19.setText("Se vozim nad 20 do vključno 30km ");
b20.setText("Se vozim nad 30 do vključno 40km ");
b21.setText("Se vozim nad 40km ");
b22.setText("Bivam v bližini šole (manj kot 5km) ");
l7.setText("Sem/Bom štipendist z posebnimi potrebami?");
b23.setText("Da");
b24.setText("Ne");
button.setText("Izračunaj!");
l1.setSize(200,20);
b1.setSize(200,20);
b2.setSize(200,20);
l2.setSize(200,20);
b3.setSize(200,20);
b4.setSize(200,20);
l3.setSize(300,20);
b5.setSize(200,20);
b6.setSize(200,20);
b7.setSize(200,20);
b8.setSize(200,20);
b9.setSize(200,20);
l4.setSize(330,20);
b10.setSize(200,20);
b11.setSize(200,20);
l5.setSize(330,20);
b12.setSize(300,20);
b13.setSize(200,20);
b14.setSize(200,20);
l6.setSize(330,20);
b15.setSize(300,20);
b16.setSize(300,20);
b17.setSize(300,20);
b18.setSize(300,20);
b19.setSize(300,20);
b20.setSize(300,20);
b21.setSize(300,20);
b22.setSize(300,20);
l7.setSize(330,20);
b23.setSize(300,20);
b24.setSize(300,20);
button.setSize(100, 50);
button.addActionListener(this);
Container c = getContentPane();
c.add(l1);
c.add(b1);
c.add(b2);
c.add(l2);
c.add(b3);
c.add(b4);
c.add(l3);
c.add(b5);
c.add(b6);
c.add(b7);
c.add(b8);
c.add(b9);
c.add(l4);
c.add(b10);
c.add(b11);
c.add(l5);
c.add(b12);
c.add(b13);
c.add(b14);
c.add(l6);
c.add(b15);
c.add(b16);
c.add(b17);
c.add(b18);
c.add(b19);
c.add(b20);
c.add(b21);
c.add(b22);
c.add(l7);
c.add(b23);
c.add(b24);
c.add(button);
ButtonGroup g1 = new ButtonGroup();
g1.add(b1);
g1.add(b2);
ButtonGroup g2 = new ButtonGroup();
g2.add(b3);
g2.add(b4);
ButtonGroup g3 = new ButtonGroup();
g3.add(b5);
g3.add(b6);
g3.add(b7);
g3.add(b8);
g3.add(b9);
ButtonGroup g4 = new ButtonGroup();
g4.add(b10);
g4.add(b11);
ButtonGroup g5 = new ButtonGroup();
g5.add(b12);
g5.add(b13);
g5.add(b14);
ButtonGroup g6 = new ButtonGroup();
g6.add(b15);
g6.add(b16);
g6.add(b17);
g6.add(b18);
g6.add(b19);
g6.add(b20);
g6.add(b21);
g6.add(b22);
ButtonGroup g7 = new ButtonGroup();
g7.add(b23);
g7.add(b24);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
b7.addActionListener(this);
b10.addActionListener(this);
b11.addActionListener(this);
b12.addActionListener(this);
b13.addActionListener(this);
b14.addActionListener(this);
b15.addActionListener(this);
b16.addActionListener(this);
b17.addActionListener(this);
b18.addActionListener(this);
b19.addActionListener(this);
b20.addActionListener(this);
b21.addActionListener(this);
b22.addActionListener(this);
b23.addActionListener(this);
b24.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == button) {
if (b1.isSelected() && b3.isSelected()) {
total += 65.74;
System.out.println("b1 && b3");
} else if (b1.isSelected() && b4.isSelected()) {
total += 131.48;
System.out.println("b1 && b4");
} else if (b2.isSelected() && b3.isSelected()) {
total += 101.30;
System.out.println("b2 && b3");
} else if (b2.isSelected() && b4.isSelected()) {
total += 202.60;
System.out.println("b2 && b4");
}
if (b5.isSelected()) {
total += 54.96;
System.out.println("b5");
} else if (b6.isSelected()) {
total += 44.18;
System.out.println("b6");
} else if (b7.isSelected()) {
total += 32.33;
System.out.println("b7");
} else if (b8.isSelected()) {
total += 21.56;
System.out.println("b8");
}
if (b10.isSelected()) {
total += 30.17;
System.out.println("b10");
}
if (b12.isSelected()) {
total += 20.46;
System.out.println("b12");
} else if (b13.isSelected()) {
total += 37.72;
System.out.println("b13");
}
if (b15.isSelected()) {
total += 85.13;
System.out.println("b15");
} else if (b16.isSelected()) {
total += 48.50;
System.out.println("b16");
} else if (b17.isSelected()) {
total += 59.27;
System.out.println("b17");
} else if (b18.isSelected()) {
total += 70.05;
System.out.println("b18");
} else if (b19.isSelected()) {
total += 80.83;
System.out.println("b19");
} else if (b20.isSelected()) {
total += 91.61;
System.out.println("b20");
} else if (b21.isSelected()) {
total += 100.04;
System.out.println("b21");
}
if (b23.isSelected()) {
total += 50.65;
System.out.println("b23");
}
JOptionPane.showMessageDialog(null, "Višina vaše Zoisove štipendije je: " + total + "€");
button.setVisible(false);
}
}
}
|
| |
| |
Najenostavneje je rešiti tako, da se v funkcijo actionPerformed
doda za
if (source == button) { naslednja vrstica:
total = 0;
Seveda pa ne na koncu pozabiti nastaviti gumba na visible, da zakomentiraš button.setVisible(false);
|
| |
| |
hvala za nasvet problem rešen
|
| |
Prikazujem 1 od skupno 1 strani |
|