Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » Java » Wichtige Frage!

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
31.03.2003, 18:03 Uhr
~Paul
Gast


Wie muss ich folgende Datei ändern so, dass nach drücken
der Ergebnis-Taste die korrekten Ergebnisse im Pull-Down-Menue,
in den Checkboxes, im Radion-Button sowie im Textelement korrekt angezeigt
werden.

Danke für Eure Hilfe!

MfG Paul!

C++:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Quiz extends Applet {

  Panel pa;                                    
  Label l1, l2, l3, l4, l5, l6, l7;            
  Choice ch;                                    
  Checkbox cb1a, cb1b, cb1c;                    
  Checkbox cb2a, cb2b, cb2c;                  
  CheckboxGroup cbg;                            
  TextField tf;                                
  Button bu;                                  
  final Color PAN = Color.green;                
  Font fH;                                      
  boolean corr1, corr2, corr3, corr4;          

  void addComponent (Component comp, Color col, int x, int y, int w,
    int top, int left, int bottom, int right) {
    GridBagConstraints c = new GridBagConstraints();    
    c.gridx = x; c.gridy = y;                          
    c.gridwidth = w; c.gridheight = 1;                  
    c.fill = GridBagConstraints.HORIZONTAL;            
    c.anchor = GridBagConstraints.CENTER;            
    c.weightx = 1; c.weighty = 1;                      
    c.insets = new Insets(top,left,bottom,right);      
    ((GridBagLayout)pa.getLayout()).setConstraints(comp,c);
    comp.setBackground(col);                            
    comp.setFont(fH);                                  
    pa.add(comp);                                      
    }

    public void init () {
    fH = new Font("SansSerif",Font.BOLD,12);      
    setLayout(new BorderLayout());              
    pa = new Panel();                            
    pa.setLayout(new GridBagLayout());          
    pa.setBackground(PAN);                      

    l1 = new Label("1. Wie ist der Druck definiert?");
    addComponent(l1,PAN,0,0,3,10,10,0,10);        
    ch = new Choice();                          
    ch.addItem("Kraft + Fl„che");              
    ch.addItem("Kraft - Fl„che");                
    ch.addItem("Fl„che - Kraft");                
    ch.addItem("Kraft  Fl„che");                
    ch.addItem("Kraft / Fl„che");                
    ch.addItem("Fl„che / Kraft");                
    addComponent(ch,Color.white,0,1,4,0,10,0,10);

    l2 = new Label("2. Welche der folgenden Aussagen sind richtig?");
    addComponent(l2,PAN,0,2,3,10,10,0,10);        
    cb1a = new Checkbox("F = p A");              
    cb1b = new Checkbox("A = F / p");
    cb1c = new Checkbox("A = p F");
    addComponent(cb1a,PAN,0,3,1,0,10,0,10);      
    addComponent(cb1b,PAN,1,3,1,0,10,0,10);
    addComponent(cb1c,PAN,2,3,1,0,10,0,10);

    l3 = new Label("3. Welche der folgenden Einheiten ist eine SI-Einheit?");
                                                  
    addComponent(l3,PAN,0,4,3,10,10,0,10);        
    cbg = new CheckboxGroup();                  
    cb2a = new Checkbox("Torr",cbg,false);        
    cb2b = new Checkbox("Pascal",cbg,false);
    cb2c = new Checkbox("Bar",cbg,false);
    addComponent(cb2a,PAN,0,5,1,0,10,0,10);      
    addComponent(cb2b,PAN,1,5,1,0,10,0,10);
    addComponent(cb2c,PAN,2,5,1,0,10,0,10);

    l4 = new Label("4. Rechne um:");            
    addComponent(l4,PAN,0,6,1,10,10,0,0);        

    l5 = new Label("0,025 N/cmý = ");            
    addComponent(l5,PAN,1,6,1,10,0,0,0);          

    tf = new TextField(8);                      
    addComponent(tf,Color.white,2,6,1,10,0,0,0);  

    l6 = new Label("Pa");                        
    addComponent(l6,PAN,3,6,1,10,5,0,10);        

    bu = new Button("Ergebnis");                
    addComponent(bu,Color.cyan,0,7,4,10,10,0,10);

    l7 = new Label();                          
    addComponent(l7,PAN,0,8,4,10,10,10,10);      

    add("Center",pa);                          
    bu.addActionListener(new BuListener());      
    }

  

  double stringToDouble (String s) {
    StringBuffer sbuf = new StringBuffer(s);    
    double val;
    int i;
    for (i=0; i<sbuf.length(); i++)              
      if (sbuf.charAt(i) == ',')              
        sbuf.setCharAt(i,'.');                  
    try {val = Double.valueOf(sbuf.toString()).doubleValue();}
                                              
    catch (NumberFormatException e) {val = 0;}    
    return val;                                  
    }



    public void actionPerformed (ActionEvent e) {
      String s = "Folgende Aufgaben wurden richtig beantwortet:      ";

      ch.setEnabled(false);                      
      cb1a.setEnabled(false);
      cb1b.setEnabled(false);
      cb1c.setEnabled(false);
      cb2a.setEnabled(false);
      cb2b.setEnabled(false);
      cb2c.setEnabled(false);
      tf.setEnabled(false);

      corr1 = (ch.getSelectedIndex() == 4);      
      corr2 =                                  
      (cb1a.getState() && cb1b.getState() && !cb1c.getState());
      corr3 = cb2b.getState();                  
      corr4 =                                    
        (stringToDouble(tf.getText()) == 250);

      if (corr1) s += " 1. ";                    
      if (corr2) s += " 2. ";                    
      if (corr3) s += " 3. ";                  
      if (corr4) s += " 4. ";

      l7.setText(s);                          
                                              
      }

    }

  }



Bearbeitung:
Tags gesetzt

Dieser Post wurde am 21.07.2003 um 14:21 Uhr von Loddab editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
11.04.2003, 15:09 Uhr
typecast
aka loddab
(Operator)


Könntest du deine BuListener-Klasse auch noch angeben?
--
All parts should go together without forcing. ... By all means, do not use a hammer. (IBM maintenance manual, 1925)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ Java ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: