Some one should run this code and see what i want to imply.
I want to use the check box to select the kind of units to put in can some one 
help ne?
this is just one panel of a tabbed aplicaion appliction.I will use three tabs
I also want to change the font of the load label and area label.
my main problem is how to use the checkbox to select the units.
I hane already read and gonr through the checkboxdemo but i still need help

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import javax.swing.BorderFactory; 
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
import java.text.ParseException;
import javax.swing.JOptionPane;


public class Stresses implements ActionListener {
    JPanel axialMainpanel;
    JPanel torsionMainpanel;
    JPanel shearMainpanel;
    JPanel choicepanel = new JPanel();
    Border  blueline = BorderFactory.createLineBorder(Color.blue);
    ImageIcon icon0;
    ImageIcon icon1;
    ButtonGroup group;
    JLabel previewLabel;
    JTextField loadInput;
    JTextField areaInput;
    JLabel result;
    String errorMessage = " Enter decimal numbers";
    String [] units = {"Imperial","Metric"};
    JComboBox unit;
    JLabel unitLabel;
      
    public JPanel createaxialPanel(JPanel axialMainpanel){
        this.axialMainpanel = axialMainpanel;
        //creation of the choice panel
       JPanel choicepanel1 = new JPanel();
        choicepanel1.setLayout(new BoxLayout(choicepanel1, BoxLayout.Y_AXIS));
       
        TitledBorder  tb = BorderFactory.createTitledBorder(blueline, "Types");
        tb.setTitleJustification(TitledBorder.CENTER);
       tb.setTitlePosition(TitledBorder.DEFAULT_POSITION);
        
        choicepanel1.setBorder(tb);
        JRadioButton tension = new JRadioButton("Tension");
        tension.setMnemonic(KeyEvent.VK_T);
        tension.setSelected(true);
        tension.addActionListener(this);
        JRadioButton compression = new JRadioButton("Compression");
        compression.setMnemonic(KeyEvent.VK_C);
        compression.addActionListener(this);
        group = new ButtonGroup();
        group.add(tension);
        group.add(compression);
        choicepanel1.add(compression);
        choicepanel1.add(tension);
        
        
        
        //creatiom of the calc  panel
        unitLabel = new JLabel("Units");
        unit = new JComboBox(units);
        unit.setSelectedIndex(0);
        unit.addActionListener(this);
        unitLabel.setLabelFor(unit);
        JPanel calc = new JPanel();
        calc.setLayout(new GridLayout(5,1,30,30));
        
        JLabel load = new JLabel("<html><b><font size = 20,face 
=HELVATICA,Color=blue>FORCE</font></b></html>");
         loadInput = new JTextField("0");
       load.setLabelFor(loadInput);
        JLabel area = new JLabel("<html><b><font size = 20,face 
=HELVATICA,Color=blue>AREA :</font></b></html>");
         areaInput = new JTextField("3");
        area.setLabelFor(areaInput);
        result = new JLabel("0    ");
       result.setBorder(blueline);
       JButton answer = new JButton("CALCULATE");
       answer.setMnemonic(KeyEvent.VK_A);
       answer.addActionListener(this);
        calc.add(load);
        calc.add(loadInput);
        calc.add(area);
        calc.add(areaInput);
        calc.add(answer);
        calc.add(result);
        calc.add(unit);
        calc.add(unitLabel);
        
        //creation of picturelabel
        JPanel picpan = new JPanel();
       TitledBorder  tp = BorderFactory.createTitledBorder(blueline, "Preview");
       tp.setTitleJustification(TitledBorder.CENTER);
       tp.setTitlePosition(TitledBorder.DEFAULT_POSITION);
        picpan.setBorder(tp);
         previewLabel = new JLabel();
         icon0 = createImageIcon("AxialStress0.jpg");
         icon1 = createImageIcon("AxialStress1.jpg");
        previewLabel.setIcon(icon0);
        picpan.add(previewLabel);
        
        
        axialMainpanel = new JPanel(new BorderLayout(30, 30));
        axialMainpanel.setBorder(BorderFactory.createEmptyBorder());
        axialMainpanel.add(choicepanel1,BorderLayout.WEST);
        axialMainpanel.add(calc,BorderLayout.CENTER);
        axialMainpanel.add(picpan,BorderLayout.EAST);
        
    return axialMainpanel;
    }
       //actions perfomed
       public void actionPerformed(ActionEvent ev){
           if ( ev.getActionCommand()=="Tension"){
                previewLabel.setIcon(icon0);
               }else 
if(ev.getActionCommand()=="Compression"){previewLabel.setIcon(icon1);
               }
               //this is where i have the problem  
                 String UN = "N/m^2";
                     String UNi="Psi";
                   float calcVal =0.0f;
                   double loadValue=0;
                  double areaValue=0;
                   try{
                   loadValue = Double.parseDouble(loadInput.getText());
                areaValue = Double.parseDouble(areaInput.getText());
                calcVal =(float)(loadValue/areaValue);
             
            
              
               if (ev.getActionCommand()=="CALCULATE"){
                   result.setText("<html><font Color=blue>" +
                        calcVal+" " +UN+  "</font></html>" );    
               }
               }
               catch(NumberFormatException 
e){JOptionPane.showMessageDialog(null, errorMessage);
             }
             JComboBox cb = (JComboBox)ev.getSource();
             String newSelection = (String)cb.getSelectedItem();
             if(cb.getActionCommand()==newSelection){
                 UN="N/m^2";
             }else{UN =UNi;
             }
             
             
             
           }
     
     protected static ImageIcon createImageIcon(String path) {
        java.net.URL imgURL = Stresses.class.getResource(path);
        if (imgURL != null) {
            return new ImageIcon(imgURL);
        } else {
            System.err.println("Couldn't find file: " + path);
            return null;
        }
    }
    
    
   
   
  //Creatting the main GUI
   private  void createAndShowGUI() {
        JFrame.setDefaultLookAndFeelDecorated(true);
        MyLookAndFeel lk = new MyLookAndFeel();
        //Create and set up the window.
        JFrame frame = new JFrame("ENGINEERS SOLUTION-Stress/strain_V1.0.1");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       Stresses stress = new Stresses();
       JPanel AxialPane = stress.createaxialPanel(axialMainpanel);
     
      JTabbedPane tabs = new JTabbedPane();
       tabs.addTab("Axial stress",AxialPane);
       frame.add(tabs);
       frame.setMinimumSize(new Dimension (850,400));
       frame.setVisible(true);        
   }
    

   
    public static void main(String[] args) {
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                 Stresses stress = new Stresses();
                stress.createAndShowGUI();
            }
        });
       
       
    }

}


      
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to