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 ");


     }
}
}

Recommended Answers

All 6 Replies

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.

There is no better tool than a compiler for working with source 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 ");


     }
}
}

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.

it didn't run as the request.

What did happen when you compiled and executed the code?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.