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);
}
}
我们的课程作业是关于成绩的计算。
创建一个Java GUI程序,用于计算第二个
JFrame
的用户输入的共同平均值。用户将在第二帧输入他的预赛,中期,预赛和决赛等级,他的总平均值将出现。
我刚刚在这里刚刚开始使用Java进行面向对象编程的编程,我只想问一下,我应该使用哪个组件" best"作为我已创建的JTextArea
的替换,以便它可以读取数字(小数)以及我应该使用哪些事件?