how to add applet into jbuilder Application.
Hi there!
I made one applet .now i want that applet inside my jubuilder application.if paste the applet code( paint ()method) then it overrides everthing & now i m not able to see the my jbuilder component. i want in half i m able to see applet & in rest part i m able to see my jbuilder component.
i shall be thankfull to u. my code r preety simple its here:
Thanks in adva..........
import java.awt.*;
import java.lang.Math;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
public class MyAppGauge extends JFrame {
// applications use a constructor, applets use the init method
public MyAppGauge() {
super("Test Gauge");
getContentPane().add(new GaugePanel());
setSize(400, 300);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try { }
catch(Exception e) {
e.printStackTrace();
}
}
private class GaugePanel extends JPanel {
String description;
String foreground_color;
String background_color;
String title;
String start_value;
String end_value;
String gradiation;
String minor_sector_color;
String units;
//defining Colors
Color red = Color.red;
Color blue = Color.blue;
Color black = Color.black;
Color green = Color.green;
Color yellow = Color.yellow;
Color pink = Color.pink;
Color white = Color.white;
Color orange = Color.orange;
Color bgcolor = Color.white;
Color gray = Color.gray;
Color darkgray = Color.darkGray;
int inner_w = 160 ;
int inner_h = 160;
int middle_w =200;
int middle_h =200;
int outer_w = 240;
int outer_h = 240;
// These are the offsets into that grid
int inner_x = 110;
int inner_y = 130;
int middle_x = 90;
int middle_y = 110;
int outer_x = 70;
int outer_y = 90;
//these are for the drawing line
int line_x = 140;
int line_y = 120;
int line_x2 = 190;
int line_y2 = 210;
int start_angle, end_angale;
public void init(){
}
public void paintComponent(Graphics g)
{
//super.paintComponent(g);
// public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.drawString("Gauge Applet Test !", 50, 50);
g2.drawString("0", 55, 200);
g2.drawString("100",315, 200);
//draw outer guage in multiple color
g2.setColor(black);
g2.drawArc(outer_x,outer_y,outer_w,outer_h,0,180);
g2.setColor(red);
g2.fillArc(outer_x,outer_y,outer_w,outer_h,0,180);
g2.setColor(black);
g2.drawArc(outer_x,outer_y,outer_w,outer_h,0,120);
g2.setColor(blue);
g2.fillArc(outer_x,outer_y,outer_w,outer_h,0,120);
g2.setColor(black);
g2.drawArc(outer_x,outer_y,outer_w,outer_h,0,60);
g2.setColor(green);
g2.fillArc(outer_x,outer_y,outer_w,outer_h,0,60);
//draw middle guage in yellow color
g2.setColor(black);
g2.drawArc(middle_x,middle_y,middle_w,middle_h,0,180);
g2.setColor(yellow);
g2.fillArc(middle_x,middle_y,middle_w,middle_h,0,180);
//draw inner gauge in yellow color
g2.setColor(black);
g2.drawArc(inner_x,inner_y,inner_w,inner_h,0,180);
g2.setColor(red);
g2.fillArc(inner_x,inner_y,inner_w,inner_h,0,180);
//Code for Dial
g2.setColor(black);
// divide arc into five subarcs
//int width = getWidth();
//int height = getHeight();
double dia = 120; //width*5/9;
double x = 190; //(width - dia)/2;
double y = 210; //(height - dia)/2 + dia/4;
double start = 0.0;
double extent = 180.0;
//double thetaInc = extent/2;
double theta = -90.0;// zero degrees == 12 o'clock
double x0 = x ;//+ dia/2;// origin of
double y0 = y ;//+ dia/2;// circle
double r = 120;//dia/2;// radius
double x1, y1, x2, y2,x3, y3, x4, y4, x5, y5, x6, y6, x7, y7;
///\
double tip = 20.0;// head height tip to flange/____\
double flange = 4.0; // max width of the head||
double radius = 2.0; // half the shaft width||
for(int s_angle= 1; s_angle <= 3; s_angle++) {
x1 = x0 + radius * Math.cos(Math.toRadians(theta - 90));
y1 = y0 + radius * Math.sin(Math.toRadians(theta - 90));
Shape s0 = new Line2D.Double(x0, y0, x1, y1);//g2.draw(s0);
double thetaOffset = 90 - Math.toDegrees(Math.atan((r - tip - 8)/radius));
x2 = x0 + (r - tip - 8) * Math.cos(Math.toRadians(theta - thetaOffset));
y2 = y0 + (r - tip - 8) * Math.sin(Math.toRadians(theta - thetaOffset));
Shape s1 = new Line2D.Double(x1, y1, x2, y2);//g2.draw(s1);
double flangeOffset = 90 - Math.toDegrees(
Math.atan((r - tip - 8)/(radius + flange)));
x3 = x0 + (r - tip - 8) * Math.cos(Math.toRadians(theta - flangeOffset));
y3 = y0 + (r - tip - 8) * Math.sin(Math.toRadians(theta - flangeOffset));
Shape s2 = new Line2D.Double(x2, y2, x3, y3);//g2.draw(s2);
x4 = x0 + (r - 8) * Math.cos(Math.toRadians(theta));
y4 = y0 + (r - 8) * Math.sin(Math.toRadians(theta));
Shape s3 = new Line2D.Double(x3, y3, x4, y4);//g2.draw(s3);
x5 = x0 + (r - tip - 8) * Math.cos(Math.toRadians(theta + flangeOffset));
y5 = y0 + (r - tip - 8) * Math.sin(Math.toRadians(theta + flangeOffset));
Shape s4 = new Line2D.Double(x4, y4, x5, y5);//g2.draw(s4);
x6 = x0 + (r - tip - 8) * Math.cos(Math.toRadians(theta + thetaOffset));
y6 = y0 + (r - tip - 8) * Math.sin(Math.toRadians(theta + thetaOffset));
Shape s5 = new Line2D.Double(x5, y5, x6, y6);//g2.draw(s5);
x7 = x0 + radius * Math.cos(Math.toRadians(theta + 90));
y7 = y0 + radius * Math.sin(Math.toRadians(theta + 90));
Shape s6 = new Line2D.Double(x6, y6, x7, y7);//g2.draw(s6);
Shape s7 = new Line2D.Double(x7, y7, x0, y0);//g2.draw(s7);
GeneralPath needle = new GeneralPath(s0);
needle.append(s1, true);
needle.append(s2, true);
needle.append(s3, true);
needle.append(s4, true);
needle.append(s5, true);
needle.append(s6, true);
needle.append(s7, true);
g2.fill(needle);
theta+= -30;
}
/*// code for 2nd Needle
g2.setColor(gray);
double sdia = 120; //width*5/9;
double sx = 190; //(width - dia)/2;
double sy = 210; //(height - dia)/2 + dia/4;
double sstart = 0.0;
double sextent = 180.0;
double stheta = -120.0;// zero degrees == 12 o'clock
double sx0 = sx ;//+ dia/2;// origin of
double sy0 = sy ;//+ dia/2;// circle
double sr = 120;//dia/2;// radius
double sx1, sy1, sx2, sy2,sx3, sy3, sx4, sy4, sx5, sy5, sx6, sy6, sx7, sy7;
///\
double stip = 20.0;// head height tip to flange/____\
double sflange = 4.0; // max width of the head||
double sradius = 2.0; // half the shaft width||
sx1 = sx0 + sradius * Math.cos(Math.toRadians(stheta - 90));
sy1 = sy0 + sradius * Math.sin(Math.toRadians(stheta - 90));
Shape ss0 = new Line2D.Double(sx0, sy0, sx1, sy1);//g2.draw(s0);
double sthetaOffset = 90 - Math.toDegrees(Math.atan((sr - stip - 8)/sradius));
sx2 = sx0 + (sr - stip - 8) * Math.cos(Math.toRadians(stheta - sthetaOffset));
sy2 = sy0 + (sr - stip - 8) * Math.sin(Math.toRadians(stheta - sthetaOffset));
Shape ss1 = new Line2D.Double(sx1, sy1, sx2, sy2);//g2.draw(s1);
double sflangeOffset = 90 - Math.toDegrees(
Math.atan((sr - stip - 8)/(sradius + sflange)));
sx3 = sx0 + (sr - stip - 8) * Math.cos(Math.toRadians(stheta - sflangeOffset));
sy3 = sy0 + (sr - stip - 8) * Math.sin(Math.toRadians(stheta - sflangeOffset));
Shape ss2 = new Line2D.Double(sx2, sy2, sx3, sy3);//g2.draw(s2);
sx4 = sx0 + (sr - 8) * Math.cos(Math.toRadians(stheta));
sy4 = sy0 + (sr - 8) * Math.sin(Math.toRadians(stheta));
Shape ss3 = new Line2D.Double(sx3, sy3, sx4, sy4);//g2.draw(s3);
sx5 = sx0 + (sr - stip - 8) * Math.cos(Math.toRadians(stheta + sflangeOffset));
sy5 = sy0 + (sr - stip - 8) * Math.sin(Math.toRadians(stheta + sflangeOffset));
Shape ss4 = new Line2D.Double(sx4, sy4, sx5, sy5);//g2.draw(s4);
sx6 = sx0 + (sr - stip - 8) * Math.cos(Math.toRadians(stheta + sthetaOffset));
sy6 = sy0 + (sr - stip - 8) * Math.sin(Math.toRadians(stheta + sthetaOffset));
Shape ss5 = new Line2D.Double(sx5, sy5, sx6, sy6);//g2.draw(s5);
sx7 = sx0 + sradius * Math.cos(Math.toRadians(stheta + 90));
sy7 = sy0 + sradius * Math.sin(Math.toRadians(stheta + 90));
Shape ss6 = new Line2D.Double(sx6, sy6, sx7, sy7);//g2.draw(s6);
Shape ss7 = new Line2D.Double(sx7, sy7, sx0, sy0);//g2.draw(s7);
GeneralPath needle2 = new GeneralPath(ss0);
needle2.append(ss1, true);
needle2.append(ss2, true);
needle2.append(ss3, true);
needle2.append(ss4, true);
needle2.append(ss5, true);
needle2.append(ss6, true);
needle2.append(ss7, true);
g2.fill(needle2);
// code for 3rd Needle
g2.setColor(darkgray);
double tdia = 120; //width*5/9;
double tx = 190; //(width - dia)/2;
double ty = 210; //(height - dia)/2 + dia/4;
double tstart = 0.0;
double textent = 180.0;
double ttheta = -150.0;// zero degrees == 12 o'clock
double tx0 = tx ;//+ dia/2;// origin of
double ty0 = ty ;//+ dia/2;// circle
double tr = 120;//dia/2;// radius
double tx1, ty1, tx2, ty2,tx3, ty3, tx4, ty4, tx5, ty5, tx6, ty6, tx7, ty7;
///\
double ttip = 20.0;// head height tip to flange/____\
double tflange = 4.0; // max width of the head||
double tradius = 2.0; // half the shaft width||
tx1 = tx0 + tradius * Math.cos(Math.toRadians(ttheta - 90));
ty1 = ty0 + tradius * Math.sin(Math.toRadians(ttheta - 90));
Shape ts0 = new Line2D.Double(tx0, ty0, tx1, ty1);//g2.draw(ts0);
double tthetaOffset = 90 - Math.toDegrees(Math.atan((tr - ttip - 8)/tradius));
tx2 = tx0 + (tr - ttip - 8) * Math.cos(Math.toRadians(ttheta - tthetaOffset));
ty2 = ty0 + (tr - ttip - 8) * Math.sin(Math.toRadians(ttheta - tthetaOffset));
Shape ts1 = new Line2D.Double(tx1, ty1, tx2, ty2);//g2.draw(ts1);
double tflangeOffset = 90 - Math.toDegrees(
Math.atan((tr - ttip - 8)/(tradius + tflange)));
tx3 = tx0 + (tr - ttip - 8) * Math.cos(Math.toRadians(ttheta - tflangeOffset));
ty3 = ty0 + (tr - ttip - 8) * Math.sin(Math.toRadians(ttheta - tflangeOffset));
Shape ts2 = new Line2D.Double(tx2, ty2, tx3, ty3);//g2.draw(ts2);
tx4 = tx0 + (tr - 8) * Math.cos(Math.toRadians(ttheta));
ty4 = ty0 + (tr - 8) * Math.sin(Math.toRadians(ttheta));
Shape ts3 = new Line2D.Double(tx3, ty3, tx4, ty4);//g2.draw(ts3);
tx5 = tx0 + (tr - ttip - 8) * Math.cos(Math.toRadians(ttheta + tflangeOffset));
ty5 = ty0 + (tr - ttip - 8) * Math.sin(Math.toRadians(ttheta + tflangeOffset));
Shape ts4 = new Line2D.Double(tx4, ty4, tx5, ty5);//g2.draw(ts4);
tx6 = tx0 + (tr - ttip - 8) * Math.cos(Math.toRadians(ttheta + tthetaOffset));
ty6 = ty0 + (tr - ttip - 8) * Math.sin(Math.toRadians(ttheta + tthetaOffset));
Shape ts5 = new Line2D.Double(tx5, ty5, tx6, ty6);//g2.draw(ts5);
tx7 = tx0 + tradius * Math.cos(Math.toRadians(ttheta + 90));
ty7 = ty0 + tradius * Math.sin(Math.toRadians(ttheta + 90));
Shape ts6 = new Line2D.Double(tx6, ty6, tx7, ty7);//g2.draw(ts6);
Shape ts7 = new Line2D.Double(tx7, ty7, tx0, ty0);//g2.draw(ts7);
GeneralPath needle3 = new GeneralPath(ts0);
needle3.append(ts1, true);
needle3.append(ts2, true);
needle3.append(ts3, true);
needle3.append(ts4, true);
needle3.append(ts5, true);
needle3.append(ts6, true);
needle3.append(ts7, true);
g2.fill(needle3);
*/
g2.setColor(black);
g2.fillOval(183,200,13 ,13);
//code for drawing ticks
g2.setColor(black);
int currAngleD = 0; //The angle, which we'll keep changing.
int endAngleD = 180; //When do we stop?
int incAngleD = 18;//Increment by 10 degrees each time.
double a = 100;//Radius
double length = 20; //Length of each line
//(h, k) is the centre
int h = 190;
int k = 210;
for(currAngleD = 0;currAngleD <= endAngleD; currAngleD+=incAngleD){
double currAngleR = Math.toRadians(currAngleD);//Convert to radians
int xx1, yy1, xx2, yy2;
xx1 = (int)(a * Math.cos(currAngleR));
yy1 = (int)(a * Math.sin(currAngleR));
xx2 = (int)((a-length) * Math.cos(currAngleR));
yy2 = (int)((a-length) * Math.sin(currAngleR));
//Got x, y. Now plot this point.
//Translatefirst. . .
//Plot
g2.drawLine(h + xx1, k - yy1, h + xx2, k - yy2);
}/// end of draw ticks(line) code
}
}
public static void main(String[] args) {
new MyAppGauge().show();
}
public void processWindowEvent(WindowEvent e) {
if(e.getID()==e.WINDOW_CLOSING)
System.exit(0);
}
}//end MyAppGauge

