java programming
1.Create a simple SWING Form to Display Student Data.The top part of the form should say “Student Information”.The middle part of the form will contain labels and textFields; one each for ID, FirstName, LastName, Email and GPA.The bottom part should have 5 Buttons that read “Find”, “Insert”, “Delete”, “Update” and “Exit”.
2.Add a few neat SWING features, like tooltips, borders, colors, etc. Also the Exit button should work and the “X” at the top right of the Window should also close the Application. Make it so that when the User clicks on the Exit Button, a MessageBox Window popup and ask the User if they are sure that they want to exit. If they say “Yes”, then Exit the App.
//BottomPanel.java
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class BottomPanel extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
JButton find = new JButton("Find");
JButton insert = new JButton("Insert");
JButton delete = new JButton("Delete");
JButton update = new JButton("Update");
JButton exit = new JButton("Exit");
protected BottomPanel(){
find.setToolTipText("Click to find
a student");
insert.setToolTipText("Click to add
student to database.");
delete.setToolTipText("Click to
delete student from database");
update.setToolTipText("Click to
update student info");
exit.setToolTipText("Click to exit
program");
exit.addActionListener(new
ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (JOptionPane.showConfirmDialog(null, "Are you
sure?", "WARNING",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
System.exit(0);
} // end if
} // end action listener event
}); // end action listener
add(find);
add(insert);
add(delete);
add(update);
add(exit);
} // end BottomPanel constructor
} // end BottomPanel class
================================================================================
//MiddlePanel.java
import javax.swing.*;
import java.awt.*;
import javax.swing.JPanel;
public class MiddlePanel extends JPanel {
protected MiddlePanel(){
setLayout(new GridLayout(5 ,
2));
setBorder(BorderFactory.createBevelBorder(1));
add(new JLabel("ID: "));
add(new JTextField());
add(new JLabel("FirstName:
"));
add(new JTextField());
add(new JLabel("Last Name:
"));
add(new JTextField());
add(new JLabel("Email: "));
add(new JTextField());
add(new JLabel("GPA: "));
add(new JTextField());
} // end MiddlePanel constructor
} // end MiddlePanel class
=============================================================================
//StudentData.java
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
public class StudentData extends JFrame{
TopPanel top = new TopPanel();
MiddlePanel mid = new MiddlePanel();
BottomPanel bottom = new BottomPanel();
public StudentData(){
JPanel p1=new JPanel();
p1.setBorder(new
EmptyBorder(10,10,10,10));
JPanel p2 = new JPanel();
p2.setLayout(new
BorderLayout());
p2.add(top,
BorderLayout.NORTH);
p2.add(mid,
BorderLayout.CENTER);
p2.add(bottom,
BorderLayout.SOUTH);
p1.add(p2);
add(p1);
} // end StudentData constructor
public static void main(String[] args) {
StudentData frame = new
StudentData();
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}// end main
}// end StudentData class
=======================================================================
//TopPanel.java
import java.awt.FlowLayout;
import java.awt.*;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class TopPanel extends JPanel {
private JLabel jLbl = new JLabel("Student
Information");
protected TopPanel(){
setLayout(new FlowLayout());
jLbl.setFont(new Font("Serif",
Font.BOLD, 24));
jLbl.setForeground(Color.GREEN);
add(jLbl);
}// end TopPanel constructor
} // end TopPanel class
======================================================================
sample output:
Get Answers For Free
Most questions answered within 1 hours.