mardi 26 avril 2016

if statements,lables and combo boxes

Ok my code has to pick route (check)display in label(check) have a return and single(check) need it to display text(check) my problem is it only prints text related to one of my statments hope come one can tell me how to fix my if statments. the lable changes on a button.It reads code by lable.

package learning;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList.*;
import java.util.Arrays.*;
import java.util.List.*;


@SuppressWarnings("unused")
public class test {

String[] items = {"Tipperary to cork ","Cork to Dublin","Limerick to Tipperary","Dublin to Cork"};
    JComboBox c = new JComboBox(items);
    JButton b = new JButton("From");
    JLabel l = new JLabel("route");

    String[] items2 = {"window","aisle"};
    JComboBox m = new JComboBox(items2); 
    JButton  n = new JButton("Seat");
    JLabel  o = new JLabel("choose seat");

    String[] items3 = {"Single","return"};
    JComboBox x = new JComboBox(items3); 
    JButton  y= new JButton("Ticket");
    JLabel  z = new JLabel("choose Ticket");

    String[] items4 = {"1","2","3","4","5","6","7","8","9","10"};
    JComboBox<?> xx = new JComboBox(items4); 
    JButton  yy = new JButton("seat");
    JLabel  zz = new JLabel("Choose a seat");
    JLabel  hh = new JLabel("cost");
    JButton  ccc = new JButton("comfirm");
    JLabel  hhh = new JLabel("");{

    }


    public test(){

        if(l.equals("Tipperary to cork")==(z.equals("single"))){
            ccc.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    hh.setText("15");                          //***only prints the text here and doesnt change to 20.

}});        
        if(l.equals("Tipperary to cork")==(z.equals("return"))){
            ccc.addActionListener(new ActionListener(){      
                public void actionPerformed(ActionEvent e){
                    hh.setText("20");                          //****

                }
            });     
        }}
    frame();

    }
     public void frame(){

    JFrame wolf = new JFrame();//frame
    wolf.setVisible(true);
    wolf.setSize(350,350);
    wolf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );

    JPanel p = new JPanel();


    p.add(hh);
    p.add(c);//
    p.add(b);//
    p.add(l);//lable1
    p.add(m);//
    p.add(n);//
    p.add(o);//lable 2
    p.add(x);//
    p.add(y);//
    p.add(z);//lable 2
    p.add(xx);//
    p.add(yy);//
    p.add(zz);//lable 2
    p.add(ccc);
    p.add(hhh);
    wolf.add(p);

    b.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
    String s = c.getSelectedItem().toString();
        l.setText(s);
        }
    });


     n.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
        String s = m.getSelectedItem().toString();
            o.setText(s);
            }
        });

     y.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
        String s = x.getSelectedItem().toString();
            z.setText(s);
            }
        });
     yy.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
        String s = xx.getSelectedItem().toString();
            zz.setText(s);
            }
        });
     }
     {
     }
public static void main(String[]args){



    new test(); 
    }
}

Aucun commentaire:

Enregistrer un commentaire