I write java codes a little ,they run and everything is ok.But still I cant understand what it means by OOPS.I fill very sorry when after seeing my codes my seniors tell that,"it runs,but this is very much procedure oriented",try adapting "object oriented " style.I have added a sample code written by me,wid reference to that,someone please explain,what oops actually means and how can I convert this code into an oops style.Thanks in regards...
Code:
import java.awt.*;
import java.awt.event.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Examples extends JApplet implements ActionListener {
JTextField jtf, jtf1;
JPasswordField pass = new JPasswordField(15);
Container contentpane = getContentPane();
String ss[] = new String[100];
JTextField jtf2, jtf3;
JLabel label1 = new JLabel("FIRST FILE");
JLabel label2 = new JLabel("SECOND FILE");
String s1[] = new String[2];
int i = 0, flag = 0,back=0;
//Frame frame1=new JFrame("LOGIN PAGE");
Container contentPane =getContentPane();
public void init() {
jtf = new JTextField(3);
jtf1 = new JTextField(15);
JPanel p1 = new JPanel(new GridLayout(3, 1));
p1.add(new JLabel("SID"));
p1.add(jtf);
p1.add(new JLabel("User name:"));
System.out.println(jtf.getText());
p1.add(jtf1);
p1.add(new JLabel("Password:"));
p1.add(pass);
contentPane.add("North", p1);
JButton submit = new JButton("SUBMIT");
submit.setActionCommand("submit");
submit.addActionListener(this);
// submit.doClick();
JButton reset = new JButton("RESET");
reset.setActionCommand("reset");
reset.addActionListener(this);
// reset.doClick();
JPanel p2 = new JPanel();
p2.add(submit);
p2.add(reset);
contentPane.add("Center", p2);
// setSize(240, 120);
}
public void actionPerformed(ActionEvent ae) {
String comm = null;
int i = 0;
comm = ae.getActionCommand();
if (comm == "submit" && i == 0) {
i++;
getValue(jtf.getText(), jtf1.getText(), pass.getText());
// System.out.println(pass.getText());
}
if (comm == "reset") {
jtf.setText("");
jtf1.setText("");
pass.setText("");
return;
}
if (comm == "submit1") {
}
if (flag == 1 && comm != "submit1"&&comm!="submit") {
s1[0] = comm;
jtf2.setText(comm);
}
if (flag == 0 && comm != "submit1"&&comm!="submit") {
s1[1] = comm;
jtf3.setText(comm);
}
flag++;
if (flag == 2)
flag = 0;
}
public void getValue(String sid, String user, String pass) {
// System.out.println(pass);
String s1 = "jdbc:oracle:thin:@157.227.93.32:1521:"+sid;
int i = 0;
try {
// System.out.println(pass);
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn = DriverManager.getConnection(s1, user,pass);
Statement stmt = conn.createStatement();
ResultSet rs = stmt
.executeQuery("select distinct TABLE_NAME from USER_CONSTRAINTS");
while (rs != null && rs.next()) {
// System.out.println(pass);
ss[i] = rs.getString("TABLE_NAME");
i++;
}
} catch (Exception e) {
JOptionPane.showConfirmDialog(null,
"ERROR LOGIN", "ERROR IN LOGIN,TRY AGAIN?", JOptionPane.YES_NO_OPTION);
//e.printStackTrace();
}
int ii = 0;
JFrame theFrame = new JFrame("SELECT TWO TABLES");
theFrame.pack();
theFrame.setVisible(true);
Container content = theFrame.getContentPane();
jtf2 = new JTextField("FIRST FILE", 15);
jtf2.setEditable(false);
jtf2.setBackground(Color.WHITE);
jtf3 = new JTextField("SECOND FILE", 15);
jtf3.setEditable(false);
jtf3.setBackground(Color.WHITE);
content.setLayout(new FlowLayout());
label1.setLabelFor(jtf);
label2.setLabelFor(jtf1);
JButton jb[] = new JButton[i];
JButton jb1 = new JButton(
"<html><body ><font type=Comic Sans MS size=5><b><i>SUBMIT</i></b></font></body></html>");
// ImageIcon icon=new ImageIcon("action.gif");
content.add(label1);
content.add(jtf2);
content.add(label2);
content.add(jtf3);
// contentPane.add(label2);
/*
* label2.setAlignmentX(10); label2.setAlignmentY(3);
*/
for (ii = 0; ii < i; ii++) {
jb[ii] = new JButton(
"<html><body ><font color=black type=Comic Sans MS size=4><b><i>"
+ ss[ii] + "</i></b></font></body></html>");
jb[ii].setActionCommand(ss[ii]);
jb[ii].addActionListener(this);
jb[ii].doClick();
jb[ii]
.setToolTipText("<html><body><font color=black type=Comic Sans MS size=4><b><i>"
+ ss[ii] + "</i></b></font></body></html>");
jb[ii].setBackground(Color.CYAN);
jb[ii].setBorderPainted(true);
jb[ii].setRequestFocusEnabled(true);
content.add(jb[ii]);
}
jb1.setActionCommand("submit1");
jb1.addActionListener(this);
jb1.doClick();
jb1
.setToolTipText("<html><body bgcolor ><font type=Comic Sans MS size=5><b><i>SUBMIT</i></b></font></body></html>");
jb1.setBackground(Color.red);
content.add(jb1);
}
}
Comment