UNIQUE COMPUTERAWT- Closeimport java.awt.*;import java.awt.event.*;public class awt_close{  public static void main(String...
UNIQUE COMPUTER                 add(exit_b);                 input_b.addActionListener(this);                 exit_b.addAc...
UNIQUE COMPUTER               add(input_b);               input_b.setBackground(Color.yellow);               input_b.setFo...
UNIQUE COMPUTERPanelimport java.awt.*;class paneldemo extends Panel{        public paneldemo()        {        }        pu...
UNIQUE COMPUTER       }       public static void main(String args[])       {                t_label t=new t_label("Testing...
UNIQUE COMPUTERApplet-String 1:import java.awt.*;import java.applet.*;/*<applet code="applet_demo2" width=300 height=100><...
UNIQUE COMPUTERpublic class applet_demo3 extends Applet implements Runnable{        String msg;        Thread t=null;     ...
Upcoming SlideShare
Loading in …5
×

Awt

432 views
357 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
432
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Awt

  1. 1. UNIQUE COMPUTERAWT- Closeimport java.awt.*;import java.awt.event.*;public class awt_close{ public static void main(String[] args){ Frame frame = new Frame("Close Operation Frame"); Label lbl = new Label("Welcome to Unique Computer: ",Label.CENTER); frame.add(lbl); frame.setSize(400,400); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } } ); }}Data-1import java.awt.*;import java.awt.event.*;class data extends Frame implements ActionListener{ TextField txt=new TextField(20); TextField txt2=new TextField(20); Label lbl=new Label("Name",Label.LEFT); Label lbl2=new Label("Output"); Button input_b=new Button("Input"); Button exit_b=new Button("Exit"); public data(String title) { super(title); setLayout(new FlowLayout()); add(lbl); add(txt); add(lbl2); txt2.setEditable(false); add(txt2); add(input_b); input_b.setBackground(Color.yellow); input_b.setForeground(Color.red);
  2. 2. UNIQUE COMPUTER add(exit_b); input_b.addActionListener(this); exit_b.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==input_b) { String a=txt.getText(); txt2.setText(a); } if(e.getSource()==exit_b) { System.exit(0); } } public static void main(String args[]) { data t=new data("Testing Component"); t.setSize(250,250); t.show(); }}Data- 2import java.awt.*;import java.awt.event.*;class data_2 extends Frame implements ActionListener{ TextField txt=new TextField(20); TextField txt2=new TextField(20); Label lbl=new Label("Name",Label.LEFT); Label lbl2=new Label("Output"); Button input_b=new Button("Input"); Button exit_b=new Button("Exit"); public data_2(String title) { super(title); setLayout(new FlowLayout()); add(lbl); add(txt); add(lbl2); txt2.setEditable(false); add(txt2);
  3. 3. UNIQUE COMPUTER add(input_b); input_b.setBackground(Color.yellow); input_b.setForeground(Color.red); add(exit_b); input_b.addActionListener(this); exit_b.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==input_b) { int num=Integer.parseInt(txt.getText()); int sq=num*num; txt2.setText(String.valueOf(sq)); } if(e.getSource()==exit_b) { System.exit(0); } } public static void main(String args[]) { data_2 t=new data_2("Testing Component"); t.setSize(250,250); t.show(); }}Frame Demoimport java.awt.*;class framedemo extends Frame{ public framedemo(String title) { super(title); } public static void main(String args[]) { framedemo obj=new framedemo("I have been Frame"); obj.setSize(500,500); obj.setVisible(true); }}
  4. 4. UNIQUE COMPUTERPanelimport java.awt.*;class paneldemo extends Panel{ public paneldemo() { } public static void main(String args[]) { paneldemo obj=new paneldemo(); Frame f=new Frame("Testing a Panel"); f.add(obj); f.setSize(500,500); f.setVisible(true); }}Labelimport java.awt.*;import java.awt.event.*;class t_label extends Frame implements ActionListener{ TextField txt=new TextField(20); Label lbl=new Label("Name"); Button exit_b=new Button("Exit"); public t_label(String title) { super(title); setLayout(new FlowLayout()); add(lbl); add(txt); System.out.println(); add(exit_b); exit_b.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==exit_b) { System.exit(0); }
  5. 5. UNIQUE COMPUTER } public static void main(String args[]) { t_label t=new t_label("Testing Component"); t.setSize(250,250); t.show(); }} APPLETApplet-Life Cycle:import java.awt.*;import java.applet.*;public class applet_demo1 extends Applet{ public void init() { setBackground(Color.cyan); setForeground(Color.red); } public void start() { } public void stop() { } public void destroy() { } public void paint(Graphics g) { }}
  6. 6. UNIQUE COMPUTERApplet-String 1:import java.awt.*;import java.applet.*;/*<applet code="applet_demo2" width=300 height=100></applet>*/public class applet_demo2 extends Applet{ String msg; public void init() { setBackground(Color.cyan); setForeground(Color.red); msg="Inside init()"; } public void start() { msg+=" Inside_Start()"; } public void stop() { } public void destroy() { } public void paint(Graphics g) { msg+=" Inside_Paint()"; g.drawString(msg,40,40); }}Applet String- Scrolling:import java.awt.*;import java.applet.*;import java.awt.event.*;import java.util.*;/*<applet code="applet_demo3" width=300 height=100></applet>*/
  7. 7. UNIQUE COMPUTERpublic class applet_demo3 extends Applet implements Runnable{ String msg; Thread t=null; char c; public void init() { setBackground(Color.cyan); setForeground(Color.red); msg=" A simple banner "; } public void start() { try { t=new Thread(this); t.start(); }catch(Exception e){} } public void stop() { } public void destroy() { } public void paint(Graphics g) { g.drawString(msg,50,50); } public void run() { for(;;) { try { repaint(); t.sleep(300); c=msg.charAt(0); msg=msg.substring(1,msg.length()); msg=msg+c; }catch(Exception e){} } }}

×