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... -
-
-
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);
-
-
}
-
-
}
-
6 1351
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);
}
}
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.
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
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |