1 | P a g e
Character Stream Classes
__________________________________________________________
 FileReader, FileWriter
 BufferedReader, BufferedWriter
 Reading from file
 The FileReader class creates a Reader that you can use to read the contents of a file.
 FileReader(String filePath)
 FileReader(File fileObj)
 Writing to File
 FileWriter(String fileName)
 FileWriter(String fileName, boolean append)
 NB:-If append is true, then the file is appended not overwritten.
IO Stream Lab Exercise
_______________________________________________________
 Writing to a File
 Note:-
 We should have a created folder on any local disk /desktop i.e. a destination where
a file is stored/write to.
 Let’s create a folder on the desktop by folder name Java_IO_File and text document
inside the folder with a given name registration.
2 | P a g e
3 | P a g e
 Jframe form for Course Registration
 Course registered and displayed on text document(Notepad)
4 | P a g e
Source code for Writing to a File
_______________________________________________________
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class REGISTRATION extends javax.swing.JFrame
{
public REGISTRATION() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel7 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
txtcoursename = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtcredit = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
cbocoursetype = new javax.swing.JComboBox();
btnsave = new javax.swing.JButton();
btnclear = new javax.swing.JButton();
btnexit = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(0, 0, 255));
jPanel1.setForeground(new java.awt.Color(255, 153, 0));
5 | P a g e
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 153, 0));
jLabel1.setText("COURSE REGISTRATION");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(203, 203, 203)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
390,Short.MAX_VALUE)
.addGap(76, 76, 76))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 11, Short.MAX_VALUE))
);
jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detail
Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Vivaldi", 1,
14), new java.awt.Color(255, 0, 255))); // NOI18N
jLabel2.setFont(new java.awt.Font("Viner Hand ITC", 1, 14)); // NOI18N
jLabel2.setText("CourseName");
jLabel3.setFont(new java.awt.Font("Viner Hand ITC", 1, 14)); // NOI18N
jLabel3.setText("CreditHr");
jLabel4.setFont(new java.awt.Font("Viner Hand ITC", 1, 14)); // NOI18N
jLabel4.setText("CourseType");
cbocoursetype.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
"Major Course", "Elective Course", "Compulsory Course", "Commom Course" }));
cbocoursetype.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
6 | P a g e
cbocoursetypeActionPerformed(evt);
}
});
btnsave.setBackground(new java.awt.Color(51, 153, 0));
btnsave.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
btnsave.setText("SAVE");
btnsave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnsaveActionPerformed(evt);
}
});
btnclear.setBackground(new java.awt.Color(51, 153, 0));
btnclear.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
btnclear.setText("CLEAR");
btnclear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnclearActionPerformed(evt);
}
});
btnexit.setBackground(new java.awt.Color(51, 153, 0));
btnexit.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
btnexit.setText("EXIT");
btnexit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnexitActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
jPanel7.setLayout(jPanel7Layout);
jPanel7Layout.setHorizontalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
7 | P a g e
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(58, 58, 58)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAI
LING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel7Layout.createSequentialGroup()
.addComponent(jLabel2)
.addGap(74, 74, 74)
.addComponent(txtcoursename))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING,
jPanel7Layout.createSequentialGroup()
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addComponent(jLabel3)
.addComponent(jLabel4))
.addGap(81, 81, 81)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD
ING)
.addComponent(cbocoursetype,
javax.swing.GroupLayout.PREFERRED_SIZE, 145,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtcredit,
javax.swing.GroupLayout.PREFERRED_SIZE, 145,
javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(106, 106, 106)
.addComponent(btnsave, javax.swing.GroupLayout.PREFERRED_SIZE,
108, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(47, 47, 47)
.addComponent(btnclear, javax.swing.GroupLayout.PREFERRED_SIZE,
98, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35)
.addComponent(btnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 98,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
8 | P a g e
jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new
java.awt.Component[] {btnclear, btnsave});
jPanel7Layout.setVerticalGroup(
jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel7Layout.createSequentialGroup()
.addGap(34, 34, 34)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)
.addComponent(jLabel2)
.addComponent(txtcoursename,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(32, 32, 32)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)
.addComponent(jLabel3)
.addComponent(txtcredit, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)
.addComponent(jLabel4)
.addComponent(cbocoursetype,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(43, 43, 43)
.addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)
.addComponent(btnsave, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
9 | P a g e
.addComponent(btnclear, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 33,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(92, Short.MAX_VALUE))
);
jPanel7Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new
java.awt.Component[] {txtcoursename, txtcredit});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void btnexitActionPerformed(java.awt.event.ActionEvent evt)
{
System.exit(0); // For exit button
}
10 | P a g e
//An action for clear button
private void btnclearActionPerformed(java.awt.event.ActionEvent evt)
{
txtcoursename.setText(" ");
txtcredit.setText(" ");
}
private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) {
String content;
int num;
content=txtcoursename.getText() + ", "+txtcredit.getText()+","+
cbocoursetype.getSelectedItem();
try {
num= Integer.parseInt(txtcredit.getText());
FileWriter fw = new
FileWriter("C:UsersAbdiDesktopJava_IO_Fileregistration.txt",true);
BufferedWriter bf = new BufferedWriter(fw);
bf.write(content);
bf.newLine();
bf.close();
JOptionPane.showMessageDialog(null,"Successfully Registered");
} catch (Exception e) {
JOptionPane.showMessageDialog(null," Wrongly coded","Plz enter correct
data",JOptionPane.WARNING_MESSAGE);
}
}
private void cbocoursetypeActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
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/uiswing/lookandfeel/plaf.html
*/
try {
11 | P a g e
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new REGISTRATION().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnclear;
private javax.swing.JButton btnexit;
private javax.swing.JButton btnsave;
private javax.swing.JComboBox cbocoursetype;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
12 | P a g e
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel7;
private javax.swing.JTextField txtcoursename;
private javax.swing.JTextField txtcredit;
// End of variables declaration
}
__________________________________________________________
 Reading from file
 Read a file from where a source is already present.
13 | P a g e
After building the design
 Jframe form for Searching Content
14 | P a g e
 Searching a desired content from the source i.e.from the folder that already created on the
desktop.
15 | P a g e
 Source code for Reading from file
_______________________________________________________
16 | P a g e

java stream class/java stream class/java stream class .pdf

  • 1.
    1 | Pa g e Character Stream Classes __________________________________________________________  FileReader, FileWriter  BufferedReader, BufferedWriter  Reading from file  The FileReader class creates a Reader that you can use to read the contents of a file.  FileReader(String filePath)  FileReader(File fileObj)  Writing to File  FileWriter(String fileName)  FileWriter(String fileName, boolean append)  NB:-If append is true, then the file is appended not overwritten. IO Stream Lab Exercise _______________________________________________________  Writing to a File  Note:-  We should have a created folder on any local disk /desktop i.e. a destination where a file is stored/write to.  Let’s create a folder on the desktop by folder name Java_IO_File and text document inside the folder with a given name registration.
  • 2.
    2 | Pa g e
  • 3.
    3 | Pa g e  Jframe form for Course Registration  Course registered and displayed on text document(Notepad)
  • 4.
    4 | Pa g e Source code for Writing to a File _______________________________________________________ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JOptionPane; public class REGISTRATION extends javax.swing.JFrame { public REGISTRATION() { initComponents(); } @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jPanel7 = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); txtcoursename = new javax.swing.JTextField(); jLabel3 = new javax.swing.JLabel(); txtcredit = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); cbocoursetype = new javax.swing.JComboBox(); btnsave = new javax.swing.JButton(); btnclear = new javax.swing.JButton(); btnexit = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jPanel1.setBackground(new java.awt.Color(0, 0, 255)); jPanel1.setForeground(new java.awt.Color(255, 153, 0));
  • 5.
    5 | Pa g e jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 153, 0)); jLabel1.setText("COURSE REGISTRATION"); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGap(203, 203, 203) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 390,Short.MAX_VALUE) .addGap(76, 76, 76)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(0, 11, Short.MAX_VALUE)) ); jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Detail Information", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Vivaldi", 1, 14), new java.awt.Color(255, 0, 255))); // NOI18N jLabel2.setFont(new java.awt.Font("Viner Hand ITC", 1, 14)); // NOI18N jLabel2.setText("CourseName"); jLabel3.setFont(new java.awt.Font("Viner Hand ITC", 1, 14)); // NOI18N jLabel3.setText("CreditHr"); jLabel4.setFont(new java.awt.Font("Viner Hand ITC", 1, 14)); // NOI18N jLabel4.setText("CourseType"); cbocoursetype.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Major Course", "Elective Course", "Compulsory Course", "Commom Course" })); cbocoursetype.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) {
  • 6.
    6 | Pa g e cbocoursetypeActionPerformed(evt); } }); btnsave.setBackground(new java.awt.Color(51, 153, 0)); btnsave.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N btnsave.setText("SAVE"); btnsave.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnsaveActionPerformed(evt); } }); btnclear.setBackground(new java.awt.Color(51, 153, 0)); btnclear.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N btnclear.setText("CLEAR"); btnclear.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnclearActionPerformed(evt); } }); btnexit.setBackground(new java.awt.Color(51, 153, 0)); btnexit.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N btnexit.setText("EXIT"); btnexit.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnexitActionPerformed(evt); } }); javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7); jPanel7.setLayout(jPanel7Layout); jPanel7Layout.setHorizontalGroup( jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup() .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD ING)
  • 7.
    7 | Pa g e .addGroup(jPanel7Layout.createSequentialGroup() .addGap(58, 58, 58) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAI LING, false) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup() .addComponent(jLabel2) .addGap(74, 74, 74) .addComponent(txtcoursename)) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel7Layout.createSequentialGroup() .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD ING) .addComponent(jLabel3) .addComponent(jLabel4)) .addGap(81, 81, 81) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEAD ING) .addComponent(cbocoursetype, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(txtcredit, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE))))) .addGroup(jPanel7Layout.createSequentialGroup() .addGap(106, 106, 106) .addComponent(btnsave, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(47, 47, 47) .addComponent(btnclear, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(35, 35, 35) .addComponent(btnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) );
  • 8.
    8 | Pa g e jPanel7Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnclear, btnsave}); jPanel7Layout.setVerticalGroup( jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel7Layout.createSequentialGroup() .addGap(34, 34, 34) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE LINE) .addComponent(jLabel2) .addComponent(txtcoursename, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(32, 32, 32) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE LINE) .addComponent(jLabel3) .addComponent(txtcredit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE LINE) .addComponent(jLabel4) .addComponent(cbocoursetype, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(43, 43, 43) .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE LINE) .addComponent(btnsave, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
  • 9.
    9 | Pa g e .addComponent(btnclear, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(btnexit, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(92, Short.MAX_VALUE)) ); jPanel7Layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {txtcoursename, txtcredit}); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jPanel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); pack(); }// </editor-fold> private void btnexitActionPerformed(java.awt.event.ActionEvent evt) { System.exit(0); // For exit button }
  • 10.
    10 | Pa g e //An action for clear button private void btnclearActionPerformed(java.awt.event.ActionEvent evt) { txtcoursename.setText(" "); txtcredit.setText(" "); } private void btnsaveActionPerformed(java.awt.event.ActionEvent evt) { String content; int num; content=txtcoursename.getText() + ", "+txtcredit.getText()+","+ cbocoursetype.getSelectedItem(); try { num= Integer.parseInt(txtcredit.getText()); FileWriter fw = new FileWriter("C:UsersAbdiDesktopJava_IO_Fileregistration.txt",true); BufferedWriter bf = new BufferedWriter(fw); bf.write(content); bf.newLine(); bf.close(); JOptionPane.showMessageDialog(null,"Successfully Registered"); } catch (Exception e) { JOptionPane.showMessageDialog(null," Wrongly coded","Plz enter correct data",JOptionPane.WARNING_MESSAGE); } } private void cbocoursetypeActionPerformed(java.awt.event.ActionEvent evt) { // TODO add your handling code here: } 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/uiswing/lookandfeel/plaf.html */ try {
  • 11.
    11 | Pa g e for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin g.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin g.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin g.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(REGISTRATION.class.getName()).log(java.util.loggin g.Level.SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new REGISTRATION().setVisible(true); } }); } // Variables declaration - do not modify private javax.swing.JButton btnclear; private javax.swing.JButton btnexit; private javax.swing.JButton btnsave; private javax.swing.JComboBox cbocoursetype; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2;
  • 12.
    12 | Pa g e private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel7; private javax.swing.JTextField txtcoursename; private javax.swing.JTextField txtcredit; // End of variables declaration } __________________________________________________________  Reading from file  Read a file from where a source is already present.
  • 13.
    13 | Pa g e After building the design  Jframe form for Searching Content
  • 14.
    14 | Pa g e  Searching a desired content from the source i.e.from the folder that already created on the desktop.
  • 15.
    15 | Pa g e  Source code for Reading from file _______________________________________________________
  • 16.
    16 | Pa g e