30, మార్చి 2012, శుక్రవారం
A SAMPLE APPLICATION DEVELOPMENT BY USING SWING COMPONENTS
//creating a shopping form
//here I am creating a sample form by using the
JApplet class in the swings
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyForm extends
JApplet implements ActionListener
{
//vars
JLabel n,a,i,lbl;
JTextField name;
JTextArea addr;
JList lst;
JButton b1,b2;
Object x[];
Container c;
String str=""
,str1="",str2="";
public void init()
{
//create frame and content
pane
JFrame jf = new JFrame();
c=jf.getContentPane();
c.setBackground(Color.yellow);
c.setLayout(null);
jf.setSize(500,400);
jf.setTitle("MyForm");
jf.setVisible(true);
//heading
lbl=new JLabel();
lbl.setForeground(Color.red);
lbl.setFont(new
Font("Dialog",Font.BOLD,36));
lbl.setText(" ONLINE
SHOPPING");
lbl.setBounds(200,10,550,40);
c.add(lbl);
//label and text fields for
name
n= new JLabel("Enter
name:",JLabel.RIGHT);
name=new JTextField(20);
n.setBounds(50,50,150,40);
name.setBounds(200,50,200,40);
c.add(n);
c.add(name);
//Label and textArea for
address
a=new JLabel("Enter
address:",JLabel.RIGHT);
addr=new JTextArea(6,20);
a.setBounds(50,100,150,40);
addr.setBounds(200,100,200,150);
c.add(addr);
c.add(a);
//a Label and ListBox for
user Selection
i=new JLabel("select
Items:",JLabel.RIGHT);
String data[]
={"T-shirts","Trousers","shorts","Jeans"};
lst=new JList(data);
i.setBounds(50,270,150,40);
lst.setBounds(200,270,200,100);
c.add(i);
c.add(lst);
//Push Buttons
b1= new
JButton("ok");
b2= new
JButton("Cancel");
b1.setBounds(200,400,150,40);
b2.setBounds(400,400,70,40);
c.add(b1);
c.add(b2);
//add ActionListener to
buttons
b1.addActionListener(this);
b2.addActionListener(this);
}
public void
actionPerformed(ActionEvent ae)
{
str=ae.getActionCommand();
if(str.equals("ok"))
{
str1+=name.getText()+"\n";
str1+=addr.getText()+"\n";
x=lst.getSelectedValues();
for(int
i=0;i<x.length;i++)
str2+=(String)x[i]+"\n";
//send the data into addr
addr.setText(str1+str2);
str1="";
str2="";
}
else
{
name.setText("");
addr.setText("");
lst.clearSelection();
}
}
}
//html file -1 it contains the above form class
<! This page contains My
form class>
<html>
<applet
code="MyForm.class" width=500 height=400>
</applet>
</html>
Another animated application
// here I am designing the animate class by using the
awt and applet conecpts
import java.awt.*;
import java.applet.*;
public class Animate extends
Applet
{
public void init()
{
}
public void paint(Graphics g)
{
Image i =
getImage(getDocumentBase(),"Gajanan.gif");
for(int x=0;x<800;x++)
{
g.drawImage(i,x,0,this);
try
{
Thread.sleep(20);
}
catch(InterruptedException
ie)
{ }
}
}
}
//html file with animate.class
<! this page contains
Animate class>
<html>
<applet
code="Animate.class" width=500 height=400>
</applet>
</html>
AWT APPLETS AND SWING COMPONENTS A QUICK REFERENCE
import java.awt.*;
import java.awt.event.*;
class wh extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
System.out.println("this is for window closing");
System.exit(0);
}
}
class frame extends Frame implements ActionListener,ItemListener
{
Checkbox c1,c2,c3,c4,c5,c6;
boolean d1,d2,d3,d4,d5,d6;
Font f1;
int x;
frame()
{
setLayout(null);
//u edit this code instead of manually repeating the same code u use for loop which is easy and reduce the length of the code and increase the readability of the program
f1=new Font("Sanserif",Font.ITALIC,20);
Label l1=new Label("enter the name",Label.LEFT);
l1.setBounds(400,400,100,10);
Label l2=new Label("father name",Label.LEFT);
l2.setBounds(400,420,100,10);
Label l3=new Label("house no",Label.LEFT);
l3.setBounds(400,440,100,10);
Label l4=new Label("street",Label.LEFT);
l4.setBounds(400,460,100,10);
Label l5=new Label("town",Label.LEFT);
l5.setBounds(400,480,100,10);
Label l6=new Label("district",Label.LEFT);
l6.setBounds(400,500,100,10);
Label l7=new Label("state",Label.LEFT);
l7.setBounds(400,520,100,10);
Label l8=new Label("E-mail",Label.LEFT);
l8.setBounds(400,540,100,10);
Label l9=new Label("mobileno",Label.LEFT);
l9.setBounds(400,560,100,10);
Label l10=new Label("this is designed by kalyan",Label.LEFT);
l10.setBounds(400,580,100,10);
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
add(l10);
Button b1=new Button("red");
b1.addActionListener(this);
b1.setBounds(700,500,50,16);
Button b2=new Button("green");
b2.setBounds(700,520,50,16);
b2.addActionListener(this);
Button b3=new Button("yellow");
b3.setBounds(700,540,50,16);
b3.addActionListener(this);
Button b4=new Button("cyan");
b4.setBounds(700,560,50,16);
b4.addActionListener(this);
Button b5=new Button("magenta");
b5.setBounds(700,480,50,16);
b5.addActionListener(this);
c1=new Checkbox("title1");
c1.addItemListener(this);
c1.setBounds(100,400,100,20);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(c1);
}
public void itemStateChanged(ItemEvent ie)
{
d1=c1.getState();
repaint();
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if(s.equals("red"))
x=1;
else
if(s.equals("green"))
x=2;
else
if(s.equals("yellow"))
x=3;
else
if(s.equals("cyan"))
x=4;
else
if(s.equals("magenta"))
x=5;
repaint();
}
public void paint(Graphics g)
{
Font f=new Font("Helvetica",Font.BOLD,14);
g.setFont(f);
g.drawString("@ramu dayinaboyina ",600,400);
g.setColor(Color.red);
g.drawString("1)D.C.M.E(Diploma in ComputerMaintainceEngg)",50,300);
g.drawString("2)D.C.E(Dipoma in Civil Engg)",50,320);
g.drawString("3)D.E.E.E(Diploma in Electrical &Electronical Engg)",50,340);
g.drawString("4)D.E.C.E(Diploma in Electronics &Electrical Engg)",50,360);
g.drawString("5)D.M.E(Diploma in Mechanical Engg)",50,380);
g.setColor(Color.green);
f=new Font("Helvetica",Font.BOLD,24);
g.setFont(f);
g.drawString("POLYTECHNIC CHIRALA" ,50,100);
g.setColor(Color.blue);
g.drawString("The Courses Offered for the year 2006-2007 are",50,200);
g.setColor(Color.cyan);
g.drawString("This is the HomePabe ",220,250);
g.drawString("this college is located in 10 acars and large buldings ,play grounds",50,260);
if(d1==true)
{
g.setColor(Color.cyan);
g.drawString("you clicked title1",40,20);
}
if(x==1)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font",400,400);
setBackground(Color.red);
}
if(x==1)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with red color",200,400);
setBackground(Color.red);
}
if(x==2)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with green color",200,400);
setBackground(Color.green);
}
if(x==3)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with yellow color",200,400);
setBackground(Color.yellow);
}
if(x==4)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with cyan color",200,400);
setBackground(Color.cyan);
}
if(x==5)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with magenta color",200,400);
setBackground(Color.magenta);
}
}
public static void main(String r[])
{
frame f=new frame();
f.setVisible(true);
f.setSize(300,250);
f.setTitle("this is an example for the java frames");
System.out.println("to exit from the program press ctrl+c");
f.setBounds(0,0,1240,860);
f.setBackground(Color.yellow);
boolean b=f.isResizable();
System.out.println("the return value is true or false for resizeing"+b);
b=f.isResizable();
System.out.println("the return value is true or false for resizeing"+b);
int c=f.getState();
System.out.println("the value of the state of the frame is "+c);
f.setState(4);
c=f.getState();
System.out.println("after setting of the the value of the state of the frame is "+c);
System.out.println("the value fo the under corated is "+b);
System.out.println("ok successfully you created the frame concept in this session");
c=f.getCursorType();
System.out.println("the style fo the cursor is "+c);
f.addWindowListener(new wh());
}}
import java.awt.event.*;
class wh extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
System.out.println("this is for window closing");
System.exit(0);
}
}
class frame extends Frame implements ActionListener,ItemListener
{
Checkbox c1,c2,c3,c4,c5,c6;
boolean d1,d2,d3,d4,d5,d6;
Font f1;
int x;
frame()
{
setLayout(null);
//u edit this code instead of manually repeating the same code u use for loop which is easy and reduce the length of the code and increase the readability of the program
f1=new Font("Sanserif",Font.ITALIC,20);
Label l1=new Label("enter the name",Label.LEFT);
l1.setBounds(400,400,100,10);
Label l2=new Label("father name",Label.LEFT);
l2.setBounds(400,420,100,10);
Label l3=new Label("house no",Label.LEFT);
l3.setBounds(400,440,100,10);
Label l4=new Label("street",Label.LEFT);
l4.setBounds(400,460,100,10);
Label l5=new Label("town",Label.LEFT);
l5.setBounds(400,480,100,10);
Label l6=new Label("district",Label.LEFT);
l6.setBounds(400,500,100,10);
Label l7=new Label("state",Label.LEFT);
l7.setBounds(400,520,100,10);
Label l8=new Label("E-mail",Label.LEFT);
l8.setBounds(400,540,100,10);
Label l9=new Label("mobileno",Label.LEFT);
l9.setBounds(400,560,100,10);
Label l10=new Label("this is designed by kalyan",Label.LEFT);
l10.setBounds(400,580,100,10);
add(l1);
add(l2);
add(l3);
add(l4);
add(l5);
add(l6);
add(l7);
add(l8);
add(l9);
add(l10);
Button b1=new Button("red");
b1.addActionListener(this);
b1.setBounds(700,500,50,16);
Button b2=new Button("green");
b2.setBounds(700,520,50,16);
b2.addActionListener(this);
Button b3=new Button("yellow");
b3.setBounds(700,540,50,16);
b3.addActionListener(this);
Button b4=new Button("cyan");
b4.setBounds(700,560,50,16);
b4.addActionListener(this);
Button b5=new Button("magenta");
b5.setBounds(700,480,50,16);
b5.addActionListener(this);
c1=new Checkbox("title1");
c1.addItemListener(this);
c1.setBounds(100,400,100,20);
add(b1);
add(b2);
add(b3);
add(b4);
add(b5);
add(c1);
}
public void itemStateChanged(ItemEvent ie)
{
d1=c1.getState();
repaint();
}
public void actionPerformed(ActionEvent ae)
{
String s=ae.getActionCommand();
if(s.equals("red"))
x=1;
else
if(s.equals("green"))
x=2;
else
if(s.equals("yellow"))
x=3;
else
if(s.equals("cyan"))
x=4;
else
if(s.equals("magenta"))
x=5;
repaint();
}
public void paint(Graphics g)
{
Font f=new Font("Helvetica",Font.BOLD,14);
g.setFont(f);
g.drawString("@ramu dayinaboyina ",600,400);
g.setColor(Color.red);
g.drawString("1)D.C.M.E(Diploma in ComputerMaintainceEngg)",50,300);
g.drawString("2)D.C.E(Dipoma in Civil Engg)",50,320);
g.drawString("3)D.E.E.E(Diploma in Electrical &Electronical Engg)",50,340);
g.drawString("4)D.E.C.E(Diploma in Electronics &Electrical Engg)",50,360);
g.drawString("5)D.M.E(Diploma in Mechanical Engg)",50,380);
g.setColor(Color.green);
f=new Font("Helvetica",Font.BOLD,24);
g.setFont(f);
g.drawString("POLYTECHNIC CHIRALA" ,50,100);
g.setColor(Color.blue);
g.drawString("The Courses Offered for the year 2006-2007 are",50,200);
g.setColor(Color.cyan);
g.drawString("This is the HomePabe ",220,250);
g.drawString("this college is located in 10 acars and large buldings ,play grounds",50,260);
if(d1==true)
{
g.setColor(Color.cyan);
g.drawString("you clicked title1",40,20);
}
if(x==1)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font",400,400);
setBackground(Color.red);
}
if(x==1)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with red color",200,400);
setBackground(Color.red);
}
if(x==2)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with green color",200,400);
setBackground(Color.green);
}
if(x==3)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with yellow color",200,400);
setBackground(Color.yellow);
}
if(x==4)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with cyan color",200,400);
setBackground(Color.cyan);
}
if(x==5)
{
g.setFont(f1);
g.drawString("you are implementing the sanserif font with magenta color",200,400);
setBackground(Color.magenta);
}
}
public static void main(String r[])
{
frame f=new frame();
f.setVisible(true);
f.setSize(300,250);
f.setTitle("this is an example for the java frames");
System.out.println("to exit from the program press ctrl+c");
f.setBounds(0,0,1240,860);
f.setBackground(Color.yellow);
boolean b=f.isResizable();
System.out.println("the return value is true or false for resizeing"+b);
b=f.isResizable();
System.out.println("the return value is true or false for resizeing"+b);
int c=f.getState();
System.out.println("the value of the state of the frame is "+c);
f.setState(4);
c=f.getState();
System.out.println("after setting of the the value of the state of the frame is "+c);
System.out.println("the value fo the under corated is "+b);
System.out.println("ok successfully you created the frame concept in this session");
c=f.getCursorType();
System.out.println("the style fo the cursor is "+c);
f.addWindowListener(new wh());
}}
SECONDARY STORAGE IMPLEMENTATION CONCEPTS IN JAVA BY USING THIS PROCEDURE U CAN SEE THE ORACLE PROCEDURE CODE AT COMMAND PROMPT THIS IS USEFUL WHILE DOING JAVA DATABASE STORED PROGRAM CONCEPT
import java.lang.*;
import java.io.*;
class emp implements Serializable
{
int eno;
String name;
double sal;
void display()
{
System.out.println(eno+"\t"+name+"\t"+sal);
}
}
public class file
{
public static void main(String
args[]) throws IOException
{
emp e=new emp();
ObjectOutputStream oos=null;
ObjectInputStream ois=null;
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
System.out.println("enter how
many employees");
int
n=Integer.parseInt(br.readLine());
oos=new ObjectOutputStream(new
BufferedOutputStream(new FileOutputStream("emp")));
try
{
for(int i=0;i<n;i++)
{
System.out.println("enter the
employee number");
e.eno=Integer.parseInt(br.readLine());
System.out.println("enter the
employee name");
e.name=br.readLine();
System.out.println("enter the
salary");
e.sal=Double.parseDouble(br.readLine());
oos.writeObject(e);
oos.reset();
}
oos.close();
}
catch(NotSerializableException ne)
{
System.out.println(ne);
}
catch(InvalidClassException ie )
{
System.out.println(ie);
}
catch(IOException ioe)
{
System.out.println(ioe);
}
System.out.println("reading
objects from the file");
ois=new ObjectInputStream(new
BufferedInputStream(new FileInputStream("emp")));
try
{
for(int i=0;i<n;i++)
{
emp e1=(emp)ois.readObject();
e1.display();
}
ois.close();
}
catch(ClassNotFoundException ce )
{
System.out.println(ce);
}
catch(IOException ioe)
{
System.out.println(ioe);
}
}//end of main();
}//end of class
SQL> select * from user_source;
NAME TYPE LINE TEXT
--------------------------------------------------------------------------------
PROC2 PROCEDURE 1 procedure proc2(n number , nm out
varchar) //this is the original source code line
PROC2 PROCEDURE 3 begin
PROC2 PROCEDURE 4 select name into nm from emp10 where
id=n;
PROC2 PROCEDURE 5 end proc2;
దీనికి సబ్స్క్రయిబ్ చేయి:
పోస్ట్లు (Atom)