0
    import java.awt.*;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextArea;

    public class ComputeGrades {

    public static void main(String []args) {
        //create a frame
        JFrame frame = new JFrame("Computation of Grades");
        frame.setSize(800,800);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);

        //add a panel
        JPanel panel = new JPanel();
        panel.setLayout(null);
        panel.setVisible(true);
        frame.add(panel);

        //Enter Full Name : JTextArea
        JLabel fName = new JLabel("Enter Full Name : ");
        fName.setBounds(0,0,100,100);
        fName.setVisible(true);
        panel.add(fName);

        JTextArea fullName = new JTextArea("ln,fn,mi.");
        fullName.setBounds(140,40,200,20);
        fullName.setVisible(true);
        panel.add(fullName);
        //Select Section : JComboBox
        JLabel sec = new JLabel("Select Section : ");
        sec.setBounds(0,30,100,100);
        sec.setVisible(true);
        panel.add(sec);

        JComboBox section = new JComboBox();
        section.setBounds(140,70,150,20);
        section.addItem("IT201M");
        section.addItem("BT403A");
        section.addItem("BT201M");
        section.addItem("BT201P");
        section.addItem("CT201A");
        section.addItem("BT203A");
        section.addItem("BT204A");
        section.addItem("BE201M");
        section.addItem("IT301P");
        section.addItem("BT403M");
        section.addItem("BS401P");
        section.setVisible(true);
        panel.add(section);
        //Enter Prelim Grade : JTextArea
        JLabel pre = new JLabel("Enter Prelim Grade : ");
        pre.setBounds(0,100,200,20);
        pre.setVisible(true);
        panel.add(pre);

        JTextArea prelim = new JTextArea("--.--");
        prelim.setBounds(140,100,150,20);
        prelim.setVisible(true);
        panel.add(prelim);
        //Enter Midterm Grade : JTextArea
        JLabel mid = new JLabel("Enter Midterm Grade : ");
        mid.setBounds(0,130,200,20);
        mid.setVisible(true);
        panel.add(mid);

        JTextArea midterm = new JTextArea("--.--");
        midterm.setBounds(140,130,150,20);
        midterm.setVisible(true);
        panel.add(midterm);
        //Enter Pre-final Grade : JTextArea
        JLabel prefi = new JLabel("Enter Pre-Finals Grade : ");
        prefi.setBounds(0,160,200,20);
        prefi.setVisible(true);
        panel.add(prefi);

        JTextArea prefinals = new JTextArea("--.--");
        prefinals.setBounds(140,160,150,20);
        prefinals.setVisible(true);
        panel.add(prefinals);
        //Enter Finals Grade : JTextArea
        JLabel fi = new JLabel("Enter Finals Grade : ");
        fi.setBounds(0,190,200,20);
        fi.setVisible(true);
        panel.add(fi);

        JTextArea finals = new JTextArea("--.--");
        finals.setBounds(140,190,150,20);
        finals.setVisible(true);
        panel.add(finals);
        //Compute for the General Average : JButton
        JLabel com = new JLabel("Click the Compute button for the General Average");
        com.setBounds(0,220,400,20);
        com.setVisible(true);
        panel.add(com);

        JButton compute = new JButton("Compute");
        compute.setBounds(0,250,100,30);
        compute.setVisible(true);
        panel.add(compute);


        }
    }

our program assignment is about computation of grades.

Create a Java GUI program that will compute the user input's general average on a second JFrame. The user will input his prelim, midterm, pre-finals and finals grade then on the second frame, his general average will appear.

I'm just new here and new on programming about Object Oriented programming in Java and I just want to ask, what component should I use "best" as replacement on JTextArea that I've created so that it can read numbers (decimals) and what events should I use?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
len
  • 1
  • 1
  • 1
    Avoid using `null` layouts, pixel perfect layouts are an illusion within modern ui design. There are too many factors which affect the individual size of components, none of which you can control. Swing was designed to work with layout managers at the core, discarding these will lead to no end of issues and problems that you will spend more and more time trying to rectify – MadProgrammer Mar 01 '15 at 07:15
  • 1
    [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) – MadProgrammer Mar 01 '15 at 07:15
  • 1
    *"what component should I use "best" as replacement on JTextArea that I've created so that it can read numbers (decimals)"* - [How to Use Formatted Text Fields](http://docs.oracle.com/javase/tutorial/uiswing/components/formattedtextfield.html) or [How to Use Spinners](http://docs.oracle.com/javase/tutorial/uiswing/components/spinner.html) – MadProgrammer Mar 01 '15 at 07:17
  • 1
    *"what events should I use?"* - [How to Write an Action Listeners](http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html) – MadProgrammer Mar 01 '15 at 07:17

0 Answers0