Welcome to Dream.In.Code
Become a Java Expert!

Join 149,944 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,418 people online right now. Registration is fast and FREE... Join Now!




java applet programming

 
Reply to this topicStart new topic

java applet programming, event handling in java applet

gyanprakash
27 Aug, 2008 - 09:12 PM
Post #1

New D.I.C Head
*

Joined: 27 Aug, 2008
Posts: 1

CODE

import java.applet.*;
import java.awt.*;
import java.lang.*;
import javax.swing.*;
import java.awt.event.*;

    public class MyApplet extends JApplet
    {
    int i=0;
    JButton b1;
    JComboBox cb1,cb2;
    JLabel l1,l2,l3;
    String st="Air",st1="Water";
    String st3="BLACK";
    public void init()
    {
    b1=new JButton("Start");
    cb1=new JComboBox();
    cb2=new JComboBox();
    l1=new JLabel("Medium 1");
    l2=new JLabel("Medium 2");
    l3=new JLabel(" ");
    cb1.addItem("Air");
    cb1.addItem("Water");
    cb1.addItem("Glass");
    cb1.addItem("Diamond");
    cb2.addItem("Air");
    cb2.addItem("Water");
    cb2.addItem("Glass");
    cb2.addItem("Diamond");
    setLayout(new FlowLayout());
    add(l1);
    add(cb1);
    cb1.addActionListener(new ChoiceClicked());
    add(l3);
    add(l2);
    add(cb2);
    cb2.addActionListener(new ChoiceClicked1());
    add(b1);
       b1.addActionListener(new ButtonClicked());
    setVisible(true);
    }
    class ChoiceClicked implements ActionListener
    {
    public void actionPerformed(ActionEvent ev)
    {
    st=(String)cb1.getSelectedItem();
    repaint();
    }
    }
    class ChoiceClicked1 implements ActionListener
    {
    public void actionPerformed(ActionEvent ev)
    {
    st1=(String)cb2.getSelectedItem();
    repaint();
    }
    }     

        class ButtonClicked implements ActionListener
    {
    public void actionPerformed(ActionEvent ev)
    {
    public void paint(Graphics g1)
        {
    Graphics2D g = (Graphics2D) g1;
    Color c=new Color(239, 0, 0, 50);
    g.setBackground(c);
    g.setColor(Color.black);
    g.drawString("REFLECTION",220,45);
    g.drawString("REFRACTION",220,365);
    g.setColor(Color.pink);
    g.fillRect(100,50,300,150);
    g.setColor(Color.black);
    g.drawString(st,125,125);
    g.setColor(Color.cyan);
    g.fillRect(100,200,300,150);
    g.setColor(Color.black);
    g.drawString(st1,125,275);
    g.setColor(Color.black);
    g.drawLine(100,200,400,200);
    g.drawLine(250,50,250,350);
    g.setColor(Color.blue);
    try
    {
    for(i=0;i<150;i++)
    {
    g.drawLine(100,50,100+i,50+i);
    Thread.sleep(20);
    }
    for(i=0;i<150;i++)
    {
    g.drawLine(250,200,250+i,200-i);
    Thread.sleep(20);
    }
    for(i=0;i<75;i++)
    {
    g.drawLine(250,200,250+i,200+2*i);
    Thread.sleep(50);
    }
    }
    catch(InterruptedException e)
    {
    }
}
}
}        





User is offlineProfile CardPM
+Quote Post

dineeshd
RE: Java Applet Programming
27 Aug, 2008 - 11:16 PM
Post #2

D.I.C Addict
Group Icon

Joined: 30 Jun, 2008
Posts: 579



Thanked: 16 times
Dream Kudos: 575
My Contributions
Are you seeking any help or contributing a code? If contributing, post it in Snippets Section. Else you need to explain what is your issue with the code.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 04:55PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month