import java.awt.*;
import javax.swing.*;
import java.text.NumberFormat;
import javax.swing.JFormattedTextField;
import java.awt.event.*;
import java.text.*;
public class Database extends JFrame
{
private JSplitPane splitPaneV;
private JSplitPane splitPaneH;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private int X1, X2, X3, X4, X5, Y;
private JLabel gradeL, equivL;
private JFormattedTextField gradeTF, equivTF;
private JButton calculateBC, clearBC;
private CalculateButtonHandlerC cbHandlerC;
private ClearButtonHandlerC clHandlerC;
private JLabel prelimL, midtermL, endtermL, finalL;
private JFormattedTextField prelimTF, midtermTF, endtermTF, finalTF;
private JButton calculateBS, clearBS;
private CalculateButtonHandlerS cbHandlerS;
private ClearButtonHandlerS clHandlerS;
private JLabel FirstNameL, LastNameL, IDNoL, GradeL, EquivL, CourseL, SubjectL, TeacherL, NoOfStudntsL;
private JTextField TeacherTF, CourseTF, SubjectTF, NoOfStudntsTF;
private JTextField[][] IDNoTF, LastNameTF, FirstNameTF, GradeTF, EquivTF;
private int index1, index2;
private JScrollPane scroll;
public void createPanel2()
{
panel2 = new JPanel();
panel2.setLayout(new GridLayout(5,2));
gradeL= new JLabel("Final Grade: ", SwingConstants.RIGHT);
equivL = new JLabel("Equivalent: ", SwingConstants.RIGHT);
NumberFormat real = NumberFormat.getNumberInstance();
real.setGroupingUsed(false);
real.setMaximumFractionDigits(2);
real.setMinimumFractionDigits(2);
gradeTF = new JFormattedTextField(real);
equivTF = new JFormattedTextField(real);
calculateBC = new JButton("Calculate");
cbHandlerC = new CalculateButtonHandlerC();
calculateBC.addActionListener(cbHandlerC);
clearBC = new JButton("Clear");
clHandlerC = new ClearButtonHandlerC();
clearBC.addActionListener(clHandlerC);
equivTF.setEditable(false);
panel2.add(gradeL);
panel2.add(gradeTF);
panel2.add(equivL);
panel2.add(equivTF);
panel2.add(calculateBC);
panel2.add(clearBC);
}
public void createPanel1()
{
panel1 = new JPanel();
panel1.setLayout(new GridLayout(5,2));
prelimL = new JLabel("Prelim Grade: ", SwingConstants.RIGHT);
midtermL = new JLabel("Midterm Grade: ", SwingConstants.RIGHT);
endtermL = new JLabel("Endterm Grade: ", SwingConstants.RIGHT);
finalL = new JLabel("Final Grade: ", SwingConstants.RIGHT);
NumberFormat real = NumberFormat.getNumberInstance();
real.setGroupingUsed(false);
real.setMaximumFractionDigits(2);
real.setMinimumFractionDigits(2);
prelimTF = new JFormattedTextField(real);
midtermTF = new JFormattedTextField(real);
endtermTF = new JFormattedTextField(real);
finalTF = new JFormattedTextField(real);
calculateBS = new JButton("Calculate");
cbHandlerS = new CalculateButtonHandlerS();
calculateBS.addActionListener(cbHandlerS);
clearBS = new JButton("Clear");
clHandlerS = new ClearButtonHandlerS();
clearBS.addActionListener(clHandlerS);
finalTF.setEditable(false);
panel1.add(prelimL);
panel1.add(prelimTF);
panel1.add(midtermL);
panel1.add(midtermTF);
panel1.add(endtermL);
panel1.add(endtermTF);
panel1.add(finalL);
panel1.add(finalTF);
panel1.add(calculateBS);
panel1.add(clearBS);
}
public void createPanel3()
{
IDNoTF = new JTextField[1][14];
LastNameTF = new JTextField[1][14];
FirstNameTF = new JTextField[1][14];
GradeTF = new JTextField[1][14];
EquivTF = new JTextField[1][14];
panel3 = new JPanel();
panel3.setLayout(null);
panel3.setSize(750,800);
TeacherL = new JLabel("TEACHER: ", SwingConstants.RIGHT);
CourseL = new JLabel("COURSE: ", SwingConstants.RIGHT);
SubjectL = new JLabel("SUBJECT: ", SwingConstants.RIGHT);
NoOfStudntsL = new JLabel("NUMBER OF STUDENTS: ", SwingConstants.LEFT);
IDNoL = new JLabel("ID #", SwingConstants.RIGHT);
FirstNameL = new JLabel("FIRST NAME", SwingConstants.RIGHT);
LastNameL = new JLabel("LAST NAME", SwingConstants.RIGHT);
GradeL = new JLabel("GRADE", SwingConstants.RIGHT);
EquivL = new JLabel("EQUIVALENT", SwingConstants.RIGHT);
TeacherTF = new JTextField();
CourseTF = new JTextField();
SubjectTF = new JTextField();
NoOfStudntsTF = new JTextField();
TeacherL.setBounds(25, 25, 70, 25);
TeacherTF.setBounds(100, 25, 250, 25);
CourseL.setBounds(25, 60, 70, 25);
CourseTF.setBounds(100, 60, 70, 25);
NoOfStudntsL.setBounds(480, 25, 140, 25);
NoOfStudntsTF.setBounds(630, 25, 30, 25);
SubjectL.setBounds(550, 60, 70, 25);
SubjectTF.setBounds(630, 60, 70, 25);
IDNoL.setBounds(80, 130, 50, 25);
LastNameL.setBounds(200, 130, 75, 25);
FirstNameL.setBounds(330, 130, 75, 25);
GradeL.setBounds(441, 130, 65, 25);
EquivL.setBounds(542, 130, 75, 25);
for(index1=0, index2=0, X1=83, X2=176, X3=310, X4=460, X5=545, Y=160 ; index2<14; index2++)
{
IDNoTF[index1][index2] = new JTextField();
LastNameTF[index1][index2] = new JTextField();
FirstNameTF[index1][index2] = new JTextField();
GradeTF[index1][index2] = new JTextField();
EquivTF[index1][index2] = new JTextField();
IDNoTF[index1][index2].setBounds(X1, Y, 75, 25);
LastNameTF[index1][index2].setBounds(X2, Y, 121, 25);
FirstNameTF[index1][index2].setBounds(X3, Y, 128, 25);
GradeTF[index1][index2].setBounds(X4, Y, 55, 25);
EquivTF[index1][index2].setBounds(X5, Y, 70, 25);
Y+=34;
panel3.add(LastNameTF[index1][index2]);
panel3.add(FirstNameTF[index1][index2]);
panel3.add(GradeTF[index1][index2]);
panel3.add(EquivTF[index1][index2]);
panel3.add(IDNoTF[index1][index2]);
}
panel3.add(TeacherL);
panel3.add(TeacherTF);
panel3.add(CourseL);
panel3.add(CourseTF);
panel3.add(NoOfStudntsL);
panel3.add(NoOfStudntsTF);
panel3.add(SubjectL);
panel3.add(SubjectTF);
panel3.add(IDNoL);
panel3.add(FirstNameL);
panel3.add(LastNameL);
panel3.add(GradeL);
panel3.add(EquivL);
}
public Database()
{
setTitle( "Database" );
JFrame frame = new JFrame("Database");
JPanel topPanel = new JPanel();
topPanel.setLayout( new BorderLayout() );
getContentPane().add( topPanel );
// Create the panels
createPanel1();
createPanel2();
createPanel3();
// Create a splitter pane
splitPaneV = new JSplitPane( JSplitPane.VERTICAL_SPLIT );
topPanel.add( splitPaneV, BorderLayout.CENTER );
splitPaneH = new JSplitPane( JSplitPane.HORIZONTAL_SPLIT );
splitPaneH.setLeftComponent( panel1 );
splitPaneH.setRightComponent( panel2 );
splitPaneV.setLeftComponent( splitPaneH );
splitPaneV.setRightComponent( panel3 );
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible( true );
setSize(750,800);
}
public static void main( String args[] )
{
// Create an instance of the test application
Database frame = new Database();
}
private class CalculateButtonHandlerC implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double grade, finalg;
grade = Double.parseDouble(gradeTF.getText());
if(grade>=99.50 && grade<101)
finalg = 1.00;
else if(grade<99.50 && grade>=98.50)
finalg = 1.10;
else if(grade<98.50 && grade>=97.50)
finalg = 1.20;
else if(grade<97.50 && grade>=96.50)
finalg = 1.30;
else if(grade<96.50 && grade>=95.50)
finalg = 1.40;
else if(grade<95.50 && grade>=94.50)
finalg = 1.50;
else if(grade<94.50 && grade>=93.50)
finalg = 1.60;
else if(grade<93.50 && grade>=92.50)
finalg = 1.70;
else if(grade<92.50 && grade>=91.50)
finalg = 1.80;
else if(grade<91.50 && grade>=90.50)
finalg = 1.90;
else if(grade<90.50 && grade>=89.50)
finalg = 2.00;
else if(grade<89.50 && grade>=88.50)
finalg = 2.10;
else if(grade<88.50 && grade>=87.50)
finalg = 2.20;
else if(grade<87.50 && grade>=86.50)
finalg = 2.30;
else if(grade<86.50 && grade>=85.50)
finalg = 2.40;
else if(grade<85.50 && grade>=84.50)
finalg = 2.50;
else if(grade<84.50 && grade>=83.50)
finalg = 2.60;
else if(grade<83.50 && grade>=82.50)
finalg = 2.70;
else if(grade<82.50 && grade>=81.50)
finalg = 2.80;
else if(grade<81.50 && grade>=80.50)
finalg = 2.90;
else if(grade<80.50 && grade>=79.50)
finalg = 3.00;
else if(grade<79.50 && grade>=78.50)
finalg = 3.10;
else if(grade<78.50 && grade>=77.50)
finalg = 3.20;
else if(grade<77.50 && grade>=76.50)
finalg = 3.30;
else if(grade<76.50 && grade>=75.50)
finalg = 3.40;
else if(grade<75.50 && grade>=74.50)
finalg = 3.50;
else
finalg = 5.0;
equivTF.setText("" + finalg);
equivTF.setEditable(false);
}
}
private class ClearButtonHandlerC implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
gradeTF.setText("");
equivTF.setText("");
}
}
private class CalculateButtonHandlerS implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double prelim, midterm, endterm, finalg;
DecimalFormat df = new DecimalFormat("#.##");
prelim = Double.parseDouble(prelimTF.getText());
midterm = Double.parseDouble(midtermTF.getText());
endterm = Double.parseDouble(endtermTF.getText());
finalg = (prelim * .30) + (midterm * .30) + (endterm * .40);
finalTF.setText("" + df.format(finalg));
finalTF.setEditable(false);
}
}
private class ClearButtonHandlerS implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
prelimTF.setText("");
midtermTF.setText("");
endtermTF.setText("");
finalTF.setText("");
}
}
}
I don't know how to put a JScrollPane in the third panel
I tried
JScrollPane scroll = new JScrollPane();
getContentPane.add(scroll) but it doesn't work