Hi Everyone,
I am developing a java application and i was wondering if anyone could help me.
I was trying to do an if statement where if i click on the view report button it checks the value if text6 is below 40, then it will display on text7 Fail. And if the value is above 40, then it will display on text7 as pass.
Here is the code below:
Please help me
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
public class Please extends JFrame implements ActionListener
{
JPanel panel;
JButton View = new JButton("View Report");
JLabel label1 = new JLabel("Student ID");
JLabel label2 = new JLabel("Name");
JLabel label3 = new JLabel("Surname");
JLabel label4 = new JLabel("Coursework %");
JLabel label5 = new JLabel("Exam %");
JLabel label6 = new JLabel("Overall Mark");
JLabel label7 = new JLabel("Grade");
JTextField text1 = new JTextField("007");
JTextField text2 = new JTextField("James");
JTextField text3 = new JTextField("Bond");
JTextField text4 = new JTextField("40");
JTextField text5 = new JTextField("50");
JTextField text6 = new JTextField("");
JTextField text7 = new JTextField("")
private JMenuBar bar = new JMenuBar();
private JMenu fileMenu = new JMenu("File");
private JMenu editMenu = new JMenu("Edit");
private JMenuItem reallyQuitChoice = new JMenuItem("Quit");
private JMenuItem modifyChoice = new JMenuItem("Modify");
public Please()
{
setTitle("Records");
bar.add(fileMenu);
bar.add(editMenu);
fileMenu.add(reallyQuitChoice);
editMenu.add(modifyChoice);
setJMenuBar(bar);
reallyQuitChoice.addActionListener(this);
modifyChoice.addActionListener(this);
panel = new JPanel(new GridLayout(7,1));
panel.add(label1);
panel.add(text1);
text1.setEditable(false);
panel.add(label2);
panel.add(text2);
text2.setEditable(false);
panel.add(label3);
panel.add(text3);
text3.setEditable(false);
panel.add(label4);
panel.add(text4);
text4.setEditable(false);
panel.add(label5);
panel.add(text5);
text5.setEditable(false);
panel.add(label6);
panel.add(text6);
text6.setEditable(false);
panel.add(label7);
panel.add(text7);
text7.setEditable(false);
add(panel,BorderLayout.CENTER);
add(View,BorderLayout.SOUTH);
View.addActionListener(this);
}
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300,400);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == View)
{
int one=Integer.parseInt(text4.getText());
int two=Integer.parseInt(text5.getText());
text6.setText(""+((one+two)/2));
}
if(e.getSource() == reallyQuitChoice)
{
System.exit(0);
}
if(e.getSource() == modifyChoice)
{
text4.setEditable(true);
text5.setEditable(true);
}
}
public static void main(String[] args)
{
new Please();
}
}