posted 20 years ago
Hello,
This is the code for my applet.Please tell me the changes for efficiency.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.net.*;
//<applet code="Pro" width=900 height=200 ></applet>
public class Pro extends Applet implements ActionListener,MouseMotionListener
{
Button jb1,jb2;
int rect1s=-1,rect1e=-1,rect2s=-1,rect2e=-1,ovals=-1,ovale=-1;
String upstream=new String("");
String downstream=new String("");
int mouseX=0,mouseY=0,x,m;
TextField tf=new TextField(20);
public void init()
{
setBackground(Color.white);
addMouseMotionListener(this);
}
public void start()
{
System.out.println("Hey it started");
}
public void paint(Graphics g)
{
rect1s=900;
rect1e=950;
rect2s=2500;
rect2e=3000;
ovals=1500;
ovale=1800;
upstream="29389";
downstream="45466";
jb1=new Button(upstream);
jb2=new Button(downstream);
x=250+(int)(500*(ovals-rect1e)/(rect2s-rect1e));
m=(int)(500*(ovale-ovals)/(rect2s-rect1e));
g.setColor(Color.magenta);
jb1.setBounds(10,100,100,30);
jb1.setBackground(Color.orange);
jb1.setForeground(Color.black);
jb1.addActionListener(this);
add(jb1);
jb2.setBounds(700,100,100,30);
jb2.setBackground(Color.orange);
jb2.setForeground(Color.black);
jb2.addActionListener(this);
add(jb2);
g.setColor(Color.pink);
g.drawLine(100,125,700,125);
g.setColor(Color.green);
g.fillOval(x-40,100,m,50);
tf.setBounds(20,20,100,20);
add(tf);
g.setColor(Color.black);
g.drawString("UPSTREAM ",30,170);
g.drawString(""+(int)ovals,x-40,170);
g.drawString(""+(int)ovale,x+m-40,170);
g.drawString("DOWNSTREAM",710,170);
g.drawString(String.valueOf(ovals-rect1e)+"bp",(200+x)/2,150);
g.drawString(String.valueOf(rect2s-ovale)+"bp",x+m+50,150);
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==jb1)
{
try
{
AppletContext ac=getAppletContext();
ac.showDocument(new URL("http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?cmd=Retrieve&db=protein&list_uids="+upstream));
}catch(Exception xe){}
}
if(e.getSource()==jb2)
{
try
{
AppletContext ac=getAppletContext();
ac.showDocument(new URL("http://www.ncbi.nlm.nih.gov:80/entrez/query.fcgi?cmd=Retrieve&db=protein&list_uids="+downstream));
}catch(Exception xe){}
}
}
public void mouseMoved(MouseEvent me)
{
mouseX=me.getX();
mouseY=me.getY();
if((mouseX>=(x-40))&&(mouseX<=500))
tf.setText("yes u got it");
else
tf.setText("");
}
public void mouseDragged(MouseEvent me){}
}
If u don't understand the code,please let me know.
thanks
chaitu