0
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 by pyTony: fixed format

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by NormR1
0

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.

0
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 by pyTony: fixed formating

0

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?

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.