0% found this document useful (0 votes)
47 views12 pages

Name: Rehan Ali Khan Roll No: BCSM-F18-068 Section: 4-B Submitted To: Sir Jawad

This document contains a student's basic information including their name (Rehan Ali Khan), roll number (BCSM-F18-068), and section (4-B). It was submitted to Sir Jawad. The document contains code for a Java program that implements a GUI form to collect and display student data.

Uploaded by

REHAN ALI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views12 pages

Name: Rehan Ali Khan Roll No: BCSM-F18-068 Section: 4-B Submitted To: Sir Jawad

This document contains a student's basic information including their name (Rehan Ali Khan), roll number (BCSM-F18-068), and section (4-B). It was submitted to Sir Jawad. The document contains code for a Java program that implements a GUI form to collect and display student data.

Uploaded by

REHAN ALI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Name:

Rehan Ali Khan


Roll No:
BCSM-F18-068
Section:
4-B
Submitted to:
Sir Jawad
Code:

import java.io.FileReader; }

import java.io.FileWriter;

import java.io.PrintWriter; /**

import java.util.ArrayList; * This method is called from within the


constructor to initialize the form.
import java.util.Scanner;
* WARNING: Do NOT modify this code. The
import javax.swing.JOptionPane;
content of this method is always

* regenerated by the Form Editor.


/*
*/
* To change this license header, choose License
@SuppressWarnings("unchecked")
Headers in Project Properties.
// <editor-fold defaultstate="collapsed"
* To change this template file, choose Tools |
desc="Generated Code">
Templates
private void initComponents() {
* and open the template in the editor.

*/
jPanel1 = new javax.swing.JPanel();

jLabel1 = new javax.swing.JLabel();


/**
jPanel2 = new javax.swing.JPanel();
*
jLabel2 = new javax.swing.JLabel();
* @author Usman Rehan Bro's
jLabel3 = new javax.swing.JLabel();
*/
jLabel4 = new javax.swing.JLabel();
public class Data extends javax.swing.JFrame {
jLabel5 = new javax.swing.JLabel();

jLabel6 = new javax.swing.JLabel();


/**
jLabel7 = new javax.swing.JLabel();
* Creates new form Data
jLabel8 = new javax.swing.JLabel();
*/
sname = new javax.swing.JTextField();
public Data() {
sroll = new javax.swing.JTextField();
initComponents();
phtext = new javax.swing.JTextField(); jLabel1.setText(" Students Basic Data");

saddress = new javax.swing.JTextField(); jLabel1.setToolTipText("");

scombo = new javax.swing.JComboBox<>(); jLabel1.setBorder(new


javax.swing.border.LineBorder(new
pcombo = new javax.swing.JComboBox<>();
java.awt.Color(0, 0, 0), 1, true));
sectcombo = new
javax.swing.JComboBox<>();
javax.swing.GroupLayout jPanel1Layout =
insertbutton = new javax.swing.JButton();
new javax.swing.GroupLayout(jPanel1);
jPanel3 = new javax.swing.JPanel();
jPanel1.setLayout(jPanel1Layout);
jButton1 = new javax.swing.JButton();
jPanel1Layout.setHorizontalGroup(
jLabel10 = new javax.swing.JLabel();

jLabel11 = new javax.swing.JLabel(); jPanel1Layout.createParallelGroup(javax.swing.


GroupLayout.Alignment.LEADING)
nph = new javax.swing.JTextField();

nadd = new javax.swing.JTextField(); .addGroup(jPanel1Layout.createSequentialGrou


jLabel12 = new javax.swing.JLabel(); p()

rnum = new javax.swing.JTextField(); .addGap(88, 88, 88)

.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 294,
javax.swing.GroupLayout.PREFERRED_SIZE)
setDefaultCloseOperation(javax.swing.Window
Constants.EXIT_ON_CLOSE);
.addContainerGap(javax.swing.GroupLayout.DE
FAULT_SIZE, Short.MAX_VALUE))
jPanel1.setBackground(new );
java.awt.Color(0, 0, 153));
jPanel1Layout.setVerticalGroup(
jPanel1.setForeground(new
java.awt.Color(0, 0, 204));
jPanel1Layout.createParallelGroup(javax.swing.
jPanel1.setToolTipText(""); GroupLayout.Alignment.LEADING)

jLabel1.setBackground(new .addGroup(jPanel1Layout.createSequentialGrou
java.awt.Color(102, 153, 255)); p()

jLabel1.setFont(new .addContainerGap()
java.awt.Font("Algerian", 3, 18)); // NOI18N .addComponent(jLabel1,
jLabel1.setForeground(new javax.swing.GroupLayout.PREFERRED_SIZE, 51,
java.awt.Color(204, 204, 255)); javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(19, scombo.setModel(new
Short.MAX_VALUE)) javax.swing.DefaultComboBoxModel<>(new
String[] { "Item 1", "Item 2", "Item 3", "Item
);
4" }));

jPanel2.setBackground(new
pcombo.setModel(new
java.awt.Color(102, 102, 255));
javax.swing.DefaultComboBoxModel<>(new
String[] { "Item 1", "Item 2", "Item 3", "Item
4" }));
jLabel2.setText("Name");

sectcombo.setModel(new
jLabel3.setText("Roll#"); javax.swing.DefaultComboBoxModel<>(new
String[] { "Item 1", "Item 2", "Item 3", "Item
4" }));
jLabel4.setText("Semester");

insertbutton.setText("Insert");
jLabel5.setText("Program");
insertbutton.addActionListener(new
java.awt.event.ActionListener() {
jLabel6.setText("Section"); public void
actionPerformed(java.awt.event.ActionEvent
evt) {
jLabel7.setText("Ph#");
insertbuttonActionPerformed(evt);

}
jLabel8.setText("Address");
});

sname.addActionListener(new
java.awt.event.ActionListener() { javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
public void
actionPerformed(java.awt.event.ActionEvent jPanel2.setLayout(jPanel2Layout);
evt) { jPanel2Layout.setHorizontalGroup(
snameActionPerformed(evt);

} jPanel2Layout.createParallelGroup(javax.swing.
GroupLayout.Alignment.LEADING)
});

.addGroup(jPanel2Layout.createSequentialGrou
p()
.addComponent(phtext)
.addGroup(jPanel2Layout.createParallelGroup(j
.addComponent(saddress)))
avax.swing.GroupLayout.Alignment.LEADING)

.addGroup(jPanel2Layout.createSequentialGrou
.addGroup(jPanel2Layout.createSequentialGrou
p()
p()
.addGap(61, 61, 61)
.addGap(38, 38, 38)
.addComponent(insertbutton)))
.addGroup(jPanel2Layout.createParallelGroup(j .addContainerGap(26,
avax.swing.GroupLayout.Alignment.TRAILING) Short.MAX_VALUE))
.addComponent(jLabel8) );
.addComponent(jLabel7) jPanel2Layout.setVerticalGroup(
.addComponent(jLabel6)
jPanel2Layout.createParallelGroup(javax.swing.
.addComponent(jLabel5)
GroupLayout.Alignment.LEADING)
.addComponent(jLabel4)

.addComponent(jLabel3) .addGroup(jPanel2Layout.createSequentialGrou
p()
.addComponent(jLabel2))
.addGap(21, 21, 21)

.addPreferredGap(javax.swing.LayoutStyle.Com
ponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.BASELINE)

.addGroup(jPanel2Layout.createParallelGroup(j .addComponent(jLabel2)
avax.swing.GroupLayout.Alignment.LEADING,
.addComponent(sname,
false)
javax.swing.GroupLayout.PREFERRED_SIZE,
.addComponent(sname) javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(sroll)

.addComponent(sectcombo, 0,
.addPreferredGap(javax.swing.LayoutStyle.Com
220, Short.MAX_VALUE)
ponentPlacement.UNRELATED)
.addComponent(pcombo, 0,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addGroup(jPanel2Layout.createParallelGroup(j
Short.MAX_VALUE)
avax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(scombo, 0,
.addComponent(jLabel3)
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE) .addComponent(sroll,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.Com
ponentPlacement.UNRELATED)

.addPreferredGap(javax.swing.LayoutStyle.Com
ponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.BASELINE)

.addGroup(jPanel2Layout.createParallelGroup(j .addComponent(jLabel7)
avax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(phtext,
.addComponent(jLabel4) javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addComponent(scombo,
javax.swing.GroupLayout.PREFERRED_SIZE))
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.Com
ponentPlacement.UNRELATED)

.addPreferredGap(javax.swing.LayoutStyle.Com
ponentPlacement.UNRELATED) .addGroup(jPanel2Layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.BASELINE)

.addGroup(jPanel2Layout.createParallelGroup(j .addComponent(jLabel8)
avax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(saddress,
.addComponent(jLabel5) javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addComponent(pcombo,
javax.swing.GroupLayout.PREFERRED_SIZE))
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, .addGap(18, 18, 18)
javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(insertbutton)

.addContainerGap(71,
.addPreferredGap(javax.swing.LayoutStyle.Com
Short.MAX_VALUE))
ponentPlacement.UNRELATED)
);
.addGroup(jPanel2Layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.BASELINE)
jButton1.setText("Delete");
.addComponent(jLabel6)
jButton1.addActionListener(new
.addComponent(sectcombo, java.awt.event.ActionListener() {
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, public void
javax.swing.GroupLayout.PREFERRED_SIZE)) actionPerformed(java.awt.event.ActionEvent
evt) {

jButton1ActionPerformed(evt);
}
.addGroup(jPanel3Layout.createSequentialGrou
});
p()

.addComponent(jLabel12)
jLabel10.setText("New Ph#");
.addPreferredGap(javax.swing.LayoutStyle.Com
ponentPlacement.UNRELATED)
jLabel11.setText("New Address");
.addComponent(rnum))

jLabel12.setText("Roll Number"); .addGroup(jPanel3Layout.createSequentialGrou


p()

rnum.addActionListener(new .addComponent(jLabel10)
java.awt.event.ActionListener() { .addGap(23, 23, 23)
public void .addComponent(nph))
actionPerformed(java.awt.event.ActionEvent
evt) {
.addGroup(jPanel3Layout.createSequentialGrou
rnumActionPerformed(evt); p()
} .addComponent(jLabel11)
});
.addPreferredGap(javax.swing.LayoutStyle.Com
ponentPlacement.RELATED)
javax.swing.GroupLayout jPanel3Layout =
new javax.swing.GroupLayout(jPanel3);
.addGroup(jPanel3Layout.createParallelGroup(j
jPanel3.setLayout(jPanel3Layout); avax.swing.GroupLayout.Alignment.LEADING)
jPanel3Layout.setHorizontalGroup(
.addGroup(jPanel3Layout.createSequentialGrou
jPanel3Layout.createParallelGroup(javax.swing. p()
GroupLayout.Alignment.LEADING) .addComponent(jButton1)

.addGap(0, 56,
.addGroup(jPanel3Layout.createSequentialGrou Short.MAX_VALUE))
p()
.addComponent(nadd))))
.addContainerGap()
.addContainerGap())

.addGroup(jPanel3Layout.createParallelGroup(j );
avax.swing.GroupLayout.Alignment.LEADING) jPanel3Layout.setVerticalGroup(
javax.swing.GroupLayout.DEFAULT_SIZE,
jPanel3Layout.createParallelGroup(javax.swing. javax.swing.GroupLayout.PREFERRED_SIZE))
GroupLayout.Alignment.LEADING)
.addGap(18, 18, 18)

.addComponent(jButton1)
.addGroup(javax.swing.GroupLayout.Alignment.
TRAILING, .addContainerGap(213,
jPanel3Layout.createSequentialGroup() Short.MAX_VALUE))
.addGap(56, 56, 56) );

.addGroup(jPanel3Layout.createParallelGroup(j
avax.swing.GroupLayout.Alignment.BASELINE) javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
.addComponent(jLabel12)
getContentPane().setLayout(layout);
.addComponent(rnum,
javax.swing.GroupLayout.PREFERRED_SIZE, layout.setHorizontalGroup(
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addPreferredGap(javax.swing.LayoutStyle.Com .addComponent(jPanel2,
ponentPlacement.RELATED) javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addGroup(jPanel3Layout.createParallelGroup(j javax.swing.GroupLayout.PREFERRED_SIZE)
avax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel10) .addGroup(layout.createSequentialGroup()

.addComponent(nph, .addGap(330, 330, 330)


javax.swing.GroupLayout.PREFERRED_SIZE, .addComponent(jPanel3,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)) javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Com .addComponent(jPanel1,
ponentPlacement.RELATED) javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
.addGroup(jPanel3Layout.createParallelGroup(j Short.MAX_VALUE)
avax.swing.GroupLayout.Alignment.BASELINE) );
.addComponent(jLabel11) layout.setVerticalGroup(
.addComponent(nadd,
javax.swing.GroupLayout.PREFERRED_SIZE, layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jPanel1, String
javax.swing.GroupLayout.PREFERRED_SIZE, seccombo=sectcombo.getSelectedItem( ).toStri
javax.swing.GroupLayout.DEFAULT_SIZE, ng();
javax.swing.GroupLayout.PREFERRED_SIZE)
String phone=phtext.getText().toString();

String
.addGroup(layout.createSequentialGroup()
address=saddress.getText().toString();
.addGap(80, 80, 80)

try{
.addGroup(layout.createParallelGroup(javax.swi
ng.GroupLayout.Alignment.LEADING)

.addComponent(jPanel2, FileWriter writer = new


javax.swing.GroupLayout.PREFERRED_SIZE, FileWriter("Data.txt" , true);
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE) writer.write(name);

.addComponent(jPanel3,
javax.swing.GroupLayout.PREFERRED_SIZE, writer.write(System.getProperty("line.separator
javax.swing.GroupLayout.DEFAULT_SIZE, "));
javax.swing.GroupLayout.PREFERRED_SIZE))) writer.write(roll);
);
writer.write(System.getProperty("line.separator
"));
pack();
writer.write(scombo1);
}// </editor-fold>

writer.write(System.getProperty("line.separator
"));
private void
insertbuttonActionPerformed(java.awt.event.Ac writer.write(pcombo2);
tionEvent evt) {

writer.write(System.getProperty("line.separator
"));
String name=sname.getText().toString();
writer.write(seccombo);
String roll=sroll.getText().toString();

String scombo1=scombo.getSelectedItem(
writer.write(System.getProperty("line.separator
).toString();
"));
String
writer.write(phone);
pcombo2=pcombo.getSelectedItem( ).toString()
;
private void
writer.write(System.getProperty("line.separator jButton1ActionPerformed(java.awt.event.Action
")); Event evt) {

writer.write(address);

writer.write(System.getProperty("line.separator
}
"));

writer.close();
private void
JOptionPane.showMessageDialog(this,
rnumActionPerformed(java.awt.event.ActionEv
"success");
ent evt) {

// TODO add your handling code here:


}
}
catch (Exception e){

JOptionPane.showMessageDialog(this,
/**
"error");
* @param args the command line arguments
}
*/

public static void main(String args[]) {

/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed"
desc=" Look and feel setting code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not


available, stay with the default look and feel.

} * For details see


http://download.oracle.com/javase/tutorial/uis
wing/lookandfeel/plaf.html
private void
*/
snameActionPerformed(java.awt.event.ActionE
vent evt) { try {

// TODO add your handling code here: for


(javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFee
} ls()) {

if ("Nimbus".equals(info.getName())) {
new Data().setVisible(true);
javax.swing.UIManager.setLookAndFeel(info.get
}
ClassName());
});
break;
}
}

}
// Variables declaration - do not modify
} catch (ClassNotFoundException ex) {
private javax.swing.JButton insertbutton;
java.util.logging.Logger.getLogger(Data.class.get private javax.swing.JButton jButton1;
Name()).log(java.util.logging.Level.SEVERE, null,
ex); private javax.swing.JLabel jLabel1;

} catch (InstantiationException ex) { private javax.swing.JLabel jLabel10;

private javax.swing.JLabel jLabel11;


java.util.logging.Logger.getLogger(Data.class.get private javax.swing.JLabel jLabel12;
Name()).log(java.util.logging.Level.SEVERE, null,
ex); private javax.swing.JLabel jLabel2;

} catch (IllegalAccessException ex) { private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;


java.util.logging.Logger.getLogger(Data.class.get private javax.swing.JLabel jLabel5;
Name()).log(java.util.logging.Level.SEVERE, null,
ex); private javax.swing.JLabel jLabel6;

} catch private javax.swing.JLabel jLabel7;


(javax.swing.UnsupportedLookAndFeelExceptio
private javax.swing.JLabel jLabel8;
n ex) {
private javax.swing.JPanel jPanel1;

java.util.logging.Logger.getLogger(Data.class.get private javax.swing.JPanel jPanel2;


Name()).log(java.util.logging.Level.SEVERE, null,
private javax.swing.JPanel jPanel3;
ex);
private javax.swing.JTextField nadd;
}
private javax.swing.JTextField nph;
//</editor-fold>
private javax.swing.JComboBox<String>
pcombo;
/* Create and display the form */
private javax.swing.JTextField phtext;
java.awt.EventQueue.invokeLater(new
private javax.swing.JTextField rnum;
Runnable() {
private javax.swing.JTextField saddress;
public void run() {
private javax.swing.JComboBox<String> private javax.swing.JTextField sname;
scombo;
private javax.swing.JTextField sroll;
private javax.swing.JComboBox<String>
// End of variables declaration
sectcombo;
}

You might also like