473,406 Members | 2,217 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Some sort of confusion!!!

hirak1984
316 100+
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...

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.sql.Connection;
  6. import java.sql.DriverManager;
  7. import java.sql.ResultSet;
  8. import java.sql.Statement;
  9.  
  10. import javax.swing.*;
  11. import javax.swing.text.JTextComponent;
  12.  
  13. public class Examples extends JApplet implements ActionListener {
  14.     JTextField jtf, jtf1;
  15.  
  16.     JPasswordField pass = new JPasswordField(15);
  17.  
  18.     Container contentpane = getContentPane();
  19.  
  20.     String ss[] = new String[100];
  21.  
  22.     JTextField jtf2, jtf3;
  23.  
  24.     JLabel label1 = new JLabel("FIRST FILE");
  25.  
  26.     JLabel label2 = new JLabel("SECOND FILE");
  27.  
  28.     String s1[] = new String[2];
  29.  
  30.     int i = 0, flag = 0,back=0;
  31.     //Frame frame1=new JFrame("LOGIN PAGE");
  32.  
  33.     Container contentPane =getContentPane();
  34.  
  35.     public void init() {
  36.  
  37.         jtf = new JTextField(3);
  38.         jtf1 = new JTextField(15);
  39.         JPanel p1 = new JPanel(new GridLayout(3, 1));
  40.         p1.add(new JLabel("SID"));
  41.         p1.add(jtf);
  42.         p1.add(new JLabel("User name:"));
  43.  
  44.         System.out.println(jtf.getText());
  45.         p1.add(jtf1);
  46.         p1.add(new JLabel("Password:"));
  47.         p1.add(pass);
  48.         contentPane.add("North", p1);
  49.         JButton submit = new JButton("SUBMIT");
  50.         submit.setActionCommand("submit");
  51.         submit.addActionListener(this);
  52.         // submit.doClick();
  53.         JButton reset = new JButton("RESET");
  54.         reset.setActionCommand("reset");
  55.         reset.addActionListener(this);
  56.         // reset.doClick();
  57.         JPanel p2 = new JPanel();
  58.         p2.add(submit);
  59.  
  60.         p2.add(reset);
  61.         contentPane.add("Center", p2);
  62.         // setSize(240, 120);
  63.  
  64.     }
  65.  
  66.     public void actionPerformed(ActionEvent ae) {
  67.         String comm = null;
  68.         int i = 0;
  69.         comm = ae.getActionCommand();
  70.         if (comm == "submit" && i == 0) {
  71.             i++;
  72.             getValue(jtf.getText(), jtf1.getText(), pass.getText());
  73.             // System.out.println(pass.getText());
  74.         }
  75.         if (comm == "reset") {
  76.             jtf.setText("");
  77.             jtf1.setText("");
  78.             pass.setText("");
  79.  
  80.             return;
  81.         }
  82.  
  83.         if (comm == "submit1") {
  84.  
  85.         }
  86.         if (flag == 1 && comm != "submit1"&&comm!="submit") {
  87.  
  88.             s1[0] = comm;
  89.             jtf2.setText(comm);
  90.         }
  91.         if (flag == 0 && comm != "submit1"&&comm!="submit") {
  92.             s1[1] = comm;
  93.             jtf3.setText(comm);
  94.         }
  95.         flag++;
  96.         if (flag == 2)
  97.             flag = 0;
  98.  
  99.     }
  100.  
  101.     public void getValue(String sid, String user, String pass) {
  102.         // System.out.println(pass);
  103.         String s1 = "jdbc:oracle:thin:@157.227.93.32:1521:"+sid;
  104.         int i = 0;
  105.         try {
  106.             // System.out.println(pass);
  107.             Class.forName("oracle.jdbc.driver.OracleDriver");
  108.             Connection conn = DriverManager.getConnection(s1, user,pass);
  109.             Statement stmt = conn.createStatement();
  110.             ResultSet rs = stmt
  111.                     .executeQuery("select distinct TABLE_NAME  from  USER_CONSTRAINTS");
  112.             while (rs != null && rs.next()) {
  113.                 // System.out.println(pass);
  114.                 ss[i] = rs.getString("TABLE_NAME");
  115.                 i++;
  116.             }
  117.  
  118.         } catch (Exception e) {
  119.             JOptionPane.showConfirmDialog(null, 
  120.                     "ERROR LOGIN", "ERROR IN LOGIN,TRY AGAIN?", JOptionPane.YES_NO_OPTION);
  121.  
  122.  
  123.             //e.printStackTrace();
  124.         }
  125.         int ii = 0;
  126.         JFrame theFrame = new JFrame("SELECT TWO TABLES");
  127.         theFrame.pack();
  128.         theFrame.setVisible(true);
  129.         Container content = theFrame.getContentPane();
  130.         jtf2 = new JTextField("FIRST FILE", 15);
  131.         jtf2.setEditable(false);
  132.         jtf2.setBackground(Color.WHITE);
  133.         jtf3 = new JTextField("SECOND FILE", 15);
  134.         jtf3.setEditable(false);
  135.         jtf3.setBackground(Color.WHITE);
  136.         content.setLayout(new FlowLayout());
  137.         label1.setLabelFor(jtf);
  138.         label2.setLabelFor(jtf1);
  139.         JButton jb[] = new JButton[i];
  140.         JButton jb1 = new JButton(
  141.                 "<html><body  ><font  type=Comic Sans MS size=5><b><i>SUBMIT</i></b></font></body></html>");
  142.         // ImageIcon icon=new ImageIcon("action.gif");
  143.         content.add(label1);
  144.         content.add(jtf2);
  145.         content.add(label2);
  146.         content.add(jtf3);
  147.  
  148.         // contentPane.add(label2);
  149.         /*
  150.          * label2.setAlignmentX(10); label2.setAlignmentY(3);
  151.          */
  152.         for (ii = 0; ii < i; ii++) {
  153.  
  154.             jb[ii] = new JButton(
  155.                     "<html><body ><font  color=black type=Comic Sans MS size=4><b><i>"
  156.                             + ss[ii] + "</i></b></font></body></html>");
  157.             jb[ii].setActionCommand(ss[ii]);
  158.             jb[ii].addActionListener(this);
  159.             jb[ii].doClick();
  160.             jb[ii]
  161.                     .setToolTipText("<html><body><font  color=black type=Comic Sans MS size=4><b><i>"
  162.                             + ss[ii] + "</i></b></font></body></html>");
  163.             jb[ii].setBackground(Color.CYAN);
  164.             jb[ii].setBorderPainted(true);
  165.  
  166.             jb[ii].setRequestFocusEnabled(true);
  167.             content.add(jb[ii]);
  168.  
  169.         }
  170.  
  171.         jb1.setActionCommand("submit1");
  172.         jb1.addActionListener(this);
  173.         jb1.doClick();
  174.         jb1
  175.                 .setToolTipText("<html><body bgcolor ><font  type=Comic Sans MS size=5><b><i>SUBMIT</i></b></font></body></html>");
  176.         jb1.setBackground(Color.red);
  177.         content.add(jb1);
  178.  
  179.     }
  180.  
  181. }
  182.  
Jan 19 '07 #1
6 1351
hirak1984
316 100+
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);

}

}
Jan 19 '07 #2
r035198x
13,262 8TB
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);

}

}
Please do not double post. OOP is not something you can learn with one snippet of code. Get a text to read about it e.g Thinking in Java or visit www.oopweb.com.
Jan 19 '07 #3
abctech
157 100+
Hi hirak1984

To get an idea about the basic difference read this article:-
http://en.wikipedia.org/wiki/Procedural_programming
Jan 20 '07 #4
hirak1984
316 100+
hey thanx for the two links.they r really helpful.But i must mention another book,which also helped me,and i hope will help others with similar queries.
it is SCJP 5 by Kathey Sierra and Bert Bates
Jan 22 '07 #5
OOPs is just an object oriented programming strategy.
In OOPs all that we handle is in the form of objects.Even when we want to access a function,or a member of a class then we need the object of that particular class.Object is just an instance of a class or they are called as basic run time entities.
Jan 22 '07 #6
r035198x
13,262 8TB
hey thanx for the two links.they r really helpful.But i must mention another book,which also helped me,and i hope will help others with similar queries.
it is SCJP 5 by Kathey Sierra and Bert Bates
Thanks for the other reference as well.
Jan 22 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: DJ Craig | last post by:
I use a web hosting service that gives me FTP access to my directory on a Linux server. I use Mac OS X. I write my code in Dreamweaver MX which gives me color-coding, but I get really tired of...
4
by: Bernard A. | last post by:
hello, i'm looking for a way to have all possible length fixed n-uples from a list, i think generators can help, but was not able to do it myself, maybe some one could point me out to an idea to...
2
by: NAJH | last post by:
I have three tables: tblBook has the fields bookID, bookRangeID, bookSubjectID, bookCode tblBookRange has the fields bookRangeID, bookRangeDescription tblBookSubject has the fields...
0
by: Stefan Turalski \(stic\) | last post by:
Hi, What I do is looking for holes in my solution to problem which is: 1. taking something from database by this sth ID, by some application 2. process it to this multithread enviroment of some...
2
by: Jensen bredal | last post by:
Hello, I'm quiet confuse after i attended a CMS course. I'm building web apps using asp.net and having looked at the version 2 of asp.net , i doubt wehter it is stil necessary to learn cms. The...
0
by: Bob | last post by:
I'm updating a fairly old Perl script. Before I change what seems to be a strange practice, I want to be sure the original author wasn't exploiting some efficiency trick. The hash %foo is used...
2
BSCode266
by: BSCode266 | last post by:
Hey everyone, Right now i am making a program for children which are physically challenged. The purpose of this program is to have children express feelings by playing. So in this game i will need...
2
by: Randy | last post by:
I have two listboxes on a form. The first box displays categories while the second box displays the items belonging to the category selected in the first box. Thus, the second box is essentially...
2
by: dav3 | last post by:
Hi folks, I am wrapping up a project that has taken me two months to complete. The last obstacle I have to face is finding a way to print something out to the user. I want this to be a pop up...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.