package ch07_auxiliaryclasses.taxcalculator;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class UPAdvisor extends JFrame implements ActionListener {

     JButton displayadvice = new JButton("Displayadvice");
     JTextField displayadviceTxt = new JTextField(11);
     JSpinner ucasPointSp = new JSpinner(new SpinnerNumberModel(0,0,180,10));
     JRadioButton Degree = new JRadioButton("Degree", true);
     JRadioButton FoundationDegree = new JRadioButton("Foundation Degree", false);
     ButtonGroup bg = new ButtonGroup();
     JTextField displayTxt = new JTextField(15);
     JButton displayBtn = new JButton("DisplayAdvice");

    public static void main(String[] args) {
        new  UPAdvisor();
    }

    public UPAdvisor() {
        setLayout(new BorderLayout());
        setSize(500, 135);
        setTitle("University of peckham course chooser");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        JPanel top= new JPanel();
        top.setLayout(new FlowLayout());
        course.addItem("Software Engineering");
        course.addItem("Computer Science");
        course.addItem("Information System");
        course.addItem("Multimedia Studies");
        top.add(course);
        add("North", top);  
        setVisible(true);

         JPanel northtop = new JPanel ();
         bg.add(Degree);
         bg.add(FoundationDegree);
        top.add(Degree);
        top.add(FoundationDegree);
        top.add(ucasPointSp);
        JPanel bottom = new JPanel();
        bottom.add(displayadvice);
       displayadvice.addActionListener(this);
       displayadviceTxt.setEditable(false);

       displayadviceTxt.setText (" sorry this no course avaiable ");

}

}

package ch07_auxiliaryclasses.taxcalculator;

public class UPAPP {


public void actionPerformed(ActionEvent e) {
        if (course.getSelectedItem().equals("software engineering")) {
            courseTxt.setText("room100");
        } else if (course.getSelectedItem().equals("computer science")) {
            courseTxt.setText("room102");
        } else if (course.getSelectedItem().equals("information system")) {
            courseTxt.setText("room103 ");

} else if 
        (course.getSelectedItem().equals("multimedia studies")) {
            courseTxt.setText(" 104 ");

        } else {

            displayadviceTxt.setText (" sorry this no course avaiable ");


     }
}
}

Edited 3 Years Ago by pyTony: fixed format

1. implement all the methods of ActionListener you should implement
2. what belongs in one class, put it in one class
3. don't use a 'course' variable without declaring one

if you just try and compile, your compiler will give you a list of errors it encounters, that can also help you improving your code.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class UPAdvisor extends JFrame implements ActionListener {

     JButton displayadvice = new JButton("Displayadvice");
     JTextField displayadviceTxt = new JTextField(11);
     JSpinner ucasPointSp = new JSpinner(new SpinnerNumberModel(0,0,180,10));
     JRadioButton Degree = new JRadioButton("Degree", true);
     JRadioButton FoundationDegree = new JRadioButton("Foundation Degree", false);
     ButtonGroup bg = new ButtonGroup();
     JTextField displayTxt = new JTextField(15);
     JButton displayBtn = new JButton("DisplayAdvice");
     JComboBox course = new JComboBox();
    public static void main(String[] args) {
        new  UPAdvisor();
    }

    public UPAdvisor() {
        setLayout(new BorderLayout());
        setSize(500, 135);
        setTitle("University of peckham course chooser");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel top= new JPanel();
        top.setLayout(new FlowLayout());
        course.addItem("Software Engineering");
        course.addItem("Computer Science");
        course.addItem("Information System");
        course.addItem("Multimedia Studies");
        top.add(course);
        add("North", top);

        setVisible(true);

         JPanel northtop = new JPanel ();
         bg.add(Degree);
         bg.add(FoundationDegree);
        top.add(Degree);
        top.add(FoundationDegree);
        top.add(ucasPointSp);
        JPanel bottom = new JPanel();
        bottom.add(displayadvice);
       displayadvice.addActionListener(this);
       displayadviceTxt.setEditable(false);

       displayadviceTxt.setText (" sorry this no course avaiable ");

}

}

public class UPAPP {



        if (course.getSelectedItem().equals("software engineering")) {
            courseTxt.setText("room100");
        } else if (course.getSelectedItem().equals("computer science")) {
            courseTxt.setText("room102");
        } else if (course.getSelectedItem().equals("information system")) {
            courseTxt.setText("room103 ");

} else if 
        (course.getSelectedItem().equals("multimedia studies")) {
            courseTxt.setText(" 104 ");

        } else {

            displayadviceTxt.setText (" sorry this no course avaiable ");


     }
}
}

Edited 3 Years Ago by pyTony: fixed formating

You forgot to post the error messages or your questions.

Have you solved all your problems? Does the code work as you want it to?

1. implement all the methods of ActionListener you should implement
2. what belongs in one class, put it in one class
3. don't use a 'course' variable without declaring one

if you just try and compile, your compiler will give you a list of errors it encounters, that can also help you improving your code.

Hi
I want to use is if-then-else statements and apply this cods in two file I did one but I am sure its wrong because it didn't run as the request.

This article has been dead for over six months. Start a new discussion instead.