|
-
Java applet to VB
Anyone can convert the below java applet into a VB program?
Thanks a lot.
// -*- Mode: Java -*-
// HelixWheelUI.java -- This applet draws an axial projection of an alpha-helix
// Author : Marcel TURCOTTE
// Created On : Sat Feb 24 13:37:47 1996
// Last Modified By: Marcel TURCOTTE
// Last Modified On: Sun Nov 10 16:00:31 1996
// © 1996 University of Florida, Marcel TURCOTTE (turcotte@chem.ufl.edu)
import java.awt.*;
import java.applet.*;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Hashtable;
import java.util.Enumeration;
import java.io.InputStream;
import java.io.IOException;
import java.io.StreamTokenizer;
import java.net.URL;
/* This is the interface to the Helix Wheel applet */
public class HelixWheelUI extends Applet {
HelixWheel helixWheel;
Scale scale;
Choice choice;
TextField textField, numberField;
Font appFont;
Label labSeq, labNum, labScale;
public void init () {
appFont = new Font ("Courier", Font.BOLD, 9);
// setBackground (Color.white);
GridBagLayout gridBag = new GridBagLayout ();
GridBagConstraints c = new GridBagConstraints ();
setLayout (gridBag);
helixWheel = new HelixWheel (this);
helixWheel.sequence = "DLLKDLEEGIQTLMGRLG";
helixWheel.startNumber = 1;
c.fill = GridBagConstraints.BOTH;
c.weighty = 1.0;
c.gridwidth = GridBagConstraints.REMAINDER;
gridBag.setConstraints (helixWheel, c);
add (helixWheel);
labSeq = new Label("Enter sequence", Label.RIGHT);
c.gridwidth = GridBagConstraints.RELATIVE;
c.weightx = 1.0;
c.weighty = 0.0;
gridBag.setConstraints (labSeq, c);
add (labSeq);
textField = new TextField (helixWheel.sequence,18);
c.gridwidth = GridBagConstraints.REMAINDER;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.WEST;
gridBag.setConstraints (textField, c);
add(textField);
labNum = new Label("Enter starting number", Label.RIGHT);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.RELATIVE;
c.weightx = 1.0;
c.weighty = 0.0;
gridBag.setConstraints (labNum, c);
add (labNum);
numberField = new TextField (Integer.toString(helixWheel.startNumber),3);
c.fill = GridBagConstraints.NONE;
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.WEST;
gridBag.setConstraints (numberField, c);
add(numberField);
labScale = new Label("Coloring scheme", Label.RIGHT);
c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.RELATIVE;
c.weightx = 1.0;
c.weighty = 0.0;
gridBag.setConstraints (labScale, c);
add (labScale);
choice = new Choice ();
// choice.setBackground (Color.white);
InputStream is = null;
String fn = getParameter ("scale");
if (fn == null)
fn = "scales.dat";
try {
is = new URL (getDocumentBase(), fn).openStream();
scale = new Scale (is);
is.close ();
} catch (Exception e) {
scale = null;
}
Scale p = Scale.hd;
while (p != null) {
choice.addItem (p.name);
p = p.next;
}
c.fill = GridBagConstraints.NONE;
c.gridwidth = GridBagConstraints.REMAINDER;
c.anchor = GridBagConstraints.WEST;
gridBag.setConstraints (choice, c);
add (choice);
textField.selectAll();
validate ();
}
public String getAppletInfo() {
String info = "Copyright © 1996 University of Florida, Author Marcel
TURCOTTE, Version 0.1";
return info;
}
public String[][] getParameterInfo () {
String info[][] = {{"Scale", "String", "Name of a file which contains
scale descriptions"}};
return info;
}
public boolean handleEvent(Event e) {
if ((e.target instanceof TextField) && (e.id == Event.ACTION_EVENT))
{
helixWheel.sequence = textField.getText().toUpperCase();
try {
helixWheel.startNumber = Integer.parseInt (numberField.getText());
} catch (NumberFormatException exception) {
helixWheel.startNumber = 1;
numberField.setText("1");
}
helixWheel.repaint();
} else if ((e.target instanceof Choice) && (e.id == Event.ACTION_EVENT))
{
scale.set(choice.getSelectedIndex());
helixWheel.repaint();
}
return super.handleEvent(e);
}
}
class HelixWheel extends Canvas {
String sequence;
int startNumber;
HelixWheelUI controller;
/* double buffering */
Dimension offDimension;
Image offImage;
Graphics offGraphics;
public HelixWheel (HelixWheelUI controller) {
super ();
this.controller = controller;
}
public Dimension preferredSize() {
return new Dimension (200, 250);
}
public Dimension minimumSize() {
return new Dimension (200, 250);
}
public void paint (Graphics g) {
update(g);
}
public void update (Graphics g) {
int seq_border, num_border, endNumber, len;
Dimension r = size ();
if ((offGraphics == null) ||
(r.width != offDimension.width) ||
(r.height != offDimension.height)) {
offDimension = r;
offImage = createImage (r.width, r.height);
offGraphics = offImage.getGraphics();
}
offGraphics.setColor (getBackground());
offGraphics.fillRect (0, 0, r.width, r.height);
offGraphics.setColor (Color.black);
FontMetrics fm = offGraphics.getFontMetrics(controller.appFont);
len = Math.min (sequence.length(), 18);
endNumber = startNumber + len - 1;
num_border = fm.stringWidth (Integer.toString (endNumber)) + 20;
seq_border = 2 * fm.stringWidth ("W");
Polar circ1 = new Polar ((r.width - seq_border + 10) / 2, - Math.PI/2);
Polar circ2 = new Polar ((r.width - 2 * seq_border) / 2, - Math.PI/2);
Polar circ3 = new Polar ((r.width - 2 * seq_border - 10) / 2, - Math.PI/2);
Polar circ4 = new Polar ((r.width - 2 * seq_border - 10 - num_border)
/ 2, - Math.PI/2);
offGraphics.drawOval (seq_border, seq_border, r.width - 2 * seq_border,
r.width - 2 * seq_border);
String str = new String (Integer.toString (startNumber) +
" - " +
Integer.toString (endNumber));
offGraphics.drawString(str, r.width / 2 - fm.stringWidth(str) / 2, r.width/2
+ fm.getHeight()/2);
for (int i = 0; i < len; i++) {
offGraphics.drawLine (r.width/2 + (int) circ2.x(),
r.width/2 + (int) circ2.y(),
r.width/2 + (int) circ3.x(),
r.width/2 + (int) circ3.y());
offGraphics.drawString(Integer.toString (startNumber + i),
r.width/2 + (int) circ4.x() - fm.stringWidth(Integer.toString(startNumber
+ i))/2,
r.width/2 + (int) circ4.y() + fm.getHeight()/2);
offGraphics.setColor(controller.scale.get(sequence.substring(i,i+1)));
offGraphics.drawString(sequence.substring(i,i+1),
r.width/2 + (int) circ1.x() - fm.stringWidth(sequence.substring(i,i+1))/2,
r.width/2 + (int) circ1.y() + fm.getHeight()/2);
offGraphics.setColor(Color.black);
circ1.theta = circ1.theta + Math.PI * 100 / 180;
circ2.theta = circ2.theta + Math.PI * 100 / 180;
circ3.theta = circ3.theta + Math.PI * 100 / 180;
circ4.theta = circ4.theta + Math.PI * 100 / 180;
}
g.drawImage (offImage, 0, 0, this);
}
}
class Scale {
String name;
Color defColor;
Hashtable values;
Scale next;
static Scale hd, tl, current;
Scale (String name) {
this.name = name;
defColor = Color.black;
values = new Hashtable();
next = null;
}
Scale (InputStream is) throws IOException {
String key = null;
int state = 1;
StreamTokenizer st = new StreamTokenizer (is);
st.commentChar ('#');
scan:
while (true) {
switch (st.nextToken ()) {
default:
System.out.println ("%%% warning uncaught token ignored: " + st.toString
());
continue scan;
case StreamTokenizer.TT_EOF:
if (state != 1)
System.out.println ("%%% warning incomplete scale");
break scan;
case '{':
if (state != 1)
System.out.println ("%%% warning unexpected token starting new scale");
state = 2;
continue scan;
case '}':
if (state == 4) {
System.out.println ("%%% warning token ',' ignored");
}
else if (state != 3)
System.out.println ("%%% warning unexpected end of of scale");
state = 1;
continue scan;
case '"':
if (state == 2) {
if (hd == null) {
current = hd = tl = this;
name = st.sval;
defColor = Color.black;
values = new Hashtable();
next = null;
}
else {
tl.next = new Scale (st.sval);
tl = tl.next;
}
state++;
}
else if (state == 6) {
tl.defColor = colorFromString (st.sval, Color.black);
state = 3;
}
else if (state == 10) {
tl.values.put (key, colorFromString (st.sval, Color.black));
state = 3;
}
else
break;
continue scan;
case ',':
if (state == 3)
state++;
else
break;
continue scan;
case StreamTokenizer.TT_WORD:
if (state == 2) {
if (hd == null) {
current = hd = tl = this;
name = st.sval;
defColor = Color.black;
values = new Hashtable();
next = null;
}
else {
tl.next = new Scale (st.sval);
tl = tl.next;
}
state++;
}
else if (state == 4 && "default".equals(st.sval))
state++;
else if (state == 4) {
key = st.sval;
state = 9;
}
else if (state == 6) {
tl.defColor = colorFromString (st.sval, Color.black);
state = 3;
}
else if (state == 10) {
tl.values.put (key, colorFromString (st.sval, Color.black));
state = 3;
}
else
break;
continue scan;
case '=':
if (state == 9 || state == 5)
state++;
else
break;
continue scan;
}
System.out.println ("%%% warning extra token ignored: " + st.toString
());
}
}
public void set (int n) {
current = hd;
for (int i=0; i<n; i++)
current = current.next;
}
public Color get (String key) {
Color v = (Color) current.values.get(key);
if (v == null)
v = current.defColor;
return v;
}
public static Color colorFromString (String s, Color defaultColor) {
Integer i;
try {
i = Integer.valueOf (s, 16);
return new Color (i.intValue());
} catch (NumberFormatException e) {
if (s.equalsIgnoreCase ("white")) {
return Color.white;
} else if (s.equalsIgnoreCase ("lightGray")) {
return Color.lightGray;
} else if (s.equalsIgnoreCase ("gray")) {
return Color.gray;
} else if (s.equalsIgnoreCase ("darkGray")) {
return Color.darkGray;
} else if (s.equalsIgnoreCase ("black")) {
return Color.black;
} else if (s.equalsIgnoreCase ("red")) {
return Color.red;
} else if (s.equalsIgnoreCase ("pink")) {
return Color.pink;
} else if (s.equalsIgnoreCase ("orange")) {
return Color.orange;
} else if (s.equalsIgnoreCase ("yellow")) {
return Color.yellow;
} else if (s.equalsIgnoreCase ("green")) {
return Color.green;
} else if (s.equalsIgnoreCase ("magenta")) {
return Color.magenta;
} else if (s.equalsIgnoreCase ("cyan")) {
return Color.cyan;
} else if (s.equalsIgnoreCase ("blue")) {
return Color.blue;
} else
return defaultColor;
}
}
}
/* Polar and cartesian representations of a point in a two dimensional space
*/
class Polar {
public double r;
public double theta;
Polar (double r, double theta) {
this.r = r;
this.theta = theta;
}
double x () {
return r * Math.cos(theta);
}
double y () {
return r * Math.sin(theta);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks