Results 1 to 15 of 15
- 08-03-2012, 08:02 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 18
- Rep Power
- 0
How to convert java standalone application into applet
Hi ,
I am newbie to java. Created a simple application and i want to run it as an applet.
Please help me out.
Here is my code....
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import javax.swing.JComponent;
import javax.swing.JFrame;
public class AffineTransformTest {
private static TransformingCanvas canvas;
public static void main(String[] args) {
JFrame frame = new JFrame();
canvas = new TransformingCanvas();
TranslateHandler translater = new TranslateHandler();
canvas.addMouseListener(translater);
canvas.addMouseMotionListener(translater);
canvas.addMouseWheelListener(new ScaleHandler());
frame.setLayout(new BorderLayout());
frame.getContentPane().add(canvas, BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_C LOSE);
frame.setVisible(true);
}
private static class TransformingCanvas extends JComponent {
private double translateX;
private double translateY;
private double scale;
TransformingCanvas() {
translateX = 0;
translateY = 0;
scale = 1;
setOpaque(true);
setDoubleBuffered(true);
}
@Override public void paint(Graphics g) {
AffineTransform tx = new AffineTransform();
tx.translate(translateX, translateY);
tx.scale(scale, scale);
Graphics2D ourGraphics = (Graphics2D) g;
ourGraphics.setColor(Color.WHITE);
ourGraphics.fillRect(0, 0, getWidth(), getHeight());
ourGraphics.setTransform(tx);
ourGraphics.setRenderingHint(RenderingHints.KEY_AN TIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
ourGraphics.setRenderingHint(RenderingHints.KEY_TE XT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
ourGraphics.setColor(Color.BLACK);
ourGraphics.drawRect(50, 50, 50, 50);
ourGraphics.fillOval(100, 100, 100, 100);
ourGraphics.drawString("Test Affine Transform", 50, 30);
// super.paint(g);
}
}
private static class TranslateHandler implements MouseListener,
MouseMotionListener {
private int lastOffsetX;
private int lastOffsetY;
public void mousePressed(MouseEvent e) {
// capture starting point
lastOffsetX = e.getX();
lastOffsetY = e.getY();
}
public void mouseDragged(MouseEvent e) {
// new x and y are defined by current mouse location subtracted
// by previously processed mouse location
int newX = e.getX() - lastOffsetX;
int newY = e.getY() - lastOffsetY;
// increment last offset to last processed by drag event.
lastOffsetX += newX;
lastOffsetY += newY;
// update the canvas locations
canvas.translateX += newX;
canvas.translateY += newY;
// schedule a repaint.
canvas.repaint();
}
public void mouseClicked(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseMoved(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
}
private static class ScaleHandler implements MouseWheelListener {
public void mouseWheelMoved(MouseWheelEvent e) {
if(e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) {
// make it a reasonable amount of zoom
// .1 gives a nice slow transition
canvas.scale += (.1 * e.getWheelRotation());
// don't cross negative threshold.
// also, setting scale to 0 has bad effects
canvas.scale = Math.max(0.00001, canvas.scale);
canvas.repaint();
}
}
}
}
- 08-03-2012, 09:09 AM #2
Re: How to convert java standalone application into applet
Why do they call it rush hour when nothing moves? - Robin Williams
- 08-03-2012, 09:13 AM #3
Re: How to convert java standalone application into applet
3½ years ago?
https://forums.oracle.com/forums/thr...readID=1262753
Don't try to take credit for someone else's code. you couldn't even apply the good advice further down in that thread.
Or did you lift it from Experts-Exchange?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-03-2012, 11:07 AM #4
Member
- Join Date
- Aug 2012
- Posts
- 18
- Rep Power
- 0
Re: How to convert java standalone application into applet
- 08-03-2012, 12:13 PM #5
Member
- Join Date
- Aug 2012
- Posts
- 18
- Rep Power
- 0
Re: How to convert java standalone application into applet
db that guy in oracle forum took it from Java2D: Have Fun With Affine Transform :)
- 08-03-2012, 12:59 PM #6
Re: How to convert java standalone application into applet
Learn Java: The Java™ Tutorials
If you already know the basics, you'll want to focus on the Java 2D and Applet deployment sections, as well as the Swing trail.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-03-2012, 01:09 PM #7
Member
- Join Date
- Aug 2012
- Posts
- 18
- Rep Power
- 0
Re: How to convert java standalone application into applet
Basically I am C programmer ....due project requirement i need to do this patch asap......just send me the code to deploy that in applet....i will atleast learn by wat you did.....I know its iritating but thats Y i knocked your forum to be straight n true....
- 08-03-2012, 01:32 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Re: How to convert java standalone application into applet
You have a project requirement to take code you found on the internet and turn it into an applet?
Please do not ask for code as refusal often offends.
- 08-03-2012, 02:08 PM #9
Member
- Join Date
- Aug 2012
- Posts
- 18
- Rep Power
- 0
Re: How to convert java standalone application into applet
No its just a prototype i took..........its just a sample..........I just want to know how can i deploy that in applets if it is standalone application......
I have my own code which works like this :
First it reads all parameters from HTML tags and stores in global variables. Then it sends query to CGI to read graph data. Then it converts data for plotting and draws graph. There is a option for user to select 1-24 hours. Based on the selection graph will be plotted by plotting only selected data. Every 30 sec it sends query to CGI for collecting data.
I need to add zooming feature in it. As it is completely in awt....so just wanna know how can i deploy a code which uses frames and all swing components........Please if you guys can stop interrogating and can just do some real work.......
- 08-03-2012, 02:51 PM #10
Re: How to convert java standalone application into applet
How can we help you learn how to write the java code you want to write?Please if you guys can stop interrogating and can just do some real work.......
If you are looking for someone to write code for you, you've come to the wrong spot.If you don't understand my response, don't ignore it, ask a question.
- 08-03-2012, 04:16 PM #11
Member
- Join Date
- Aug 2012
- Posts
- 18
- Rep Power
- 0
Re: How to convert java standalone application into applet
I am not asking to write code ..i m asking how to implement zooming with using awt classes and functions....i need the suggestion..........I have planed to use AffineTransform ...but it just zoom my image...i have graph...........i want that... when i zoom ...only the contents inside gets zoomed and accordingly x-y axis should get granualar.....Here i am bothered about granuality of x-y axis when zoom in happens so that graph ploted gives me more accurate values on x-y axis....
- 08-03-2012, 04:35 PM #12
Re: How to convert java standalone application into applet
Can you post the code you are working with as a small program that compiles, executes and shows the problem?
This part of your problem about drawing graphs and zooming should be posted in another part of the forum. This section is for applets.If you don't understand my response, don't ignore it, ask a question.
- 08-03-2012, 05:13 PM #13
Member
- Join Date
- Aug 2012
- Posts
- 18
- Rep Power
- 0
Re: How to convert java standalone application into applet
Java Code:import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.AffineTransform; import java.util.*; import java.text.*; import javax.swing.JComponent; import javax.swing.JFrame; public class AffineTransformTest { private static TransformingCanvas canvas; public static int SIZE_X = 480; public static int SIZE_Y = 250; public static int SIZE_Y1 = 240; public static int xOffset = 50; public static int yOffset = 40; public static int Y1_MAX_VALUE = 100; public static int Y2_MAX_VALUE = 3; public static int MAX_NUM_INTERVELL_PER_DAY = 96; public static int duration=1; public static int sizeY = SIZE_Y; public static void main(String[] args) { JFrame frame = new JFrame(); canvas = new TransformingCanvas(); TranslateHandler translater = new TranslateHandler(); canvas.addMouseListener(translater); canvas.addMouseMotionListener(translater); canvas.addMouseWheelListener(new ScaleHandler()); frame.setLayout(new BorderLayout()); frame.getContentPane().add(canvas, BorderLayout.CENTER); frame.setSize(500, 500); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.setVisible(true); } private static class TransformingCanvas extends JComponent { private double translateX; private double translateY; private double scale; TransformingCanvas() { translateX = 0; translateY = 0; scale = 1; setOpaque(true); setDoubleBuffered(true); } @Override public void paint(Graphics g) { Color plotColor1,plotColor2,plotColor3,plotColor4,plotColor5,plotColor6,plotColor7,plotColor8,plotColor9,plotColor10; plotColor1 = Color.orange; plotColor2 = Color.black; plotColor3 = Color.blue; plotColor4 = Color.magenta; plotColor5 = Color.cyan; plotColor6 = Color.pink; plotColor7 = Color.gray; plotColor8 = Color.red; plotColor9 = Color.green; plotColor10 = Color.lightGray; AffineTransform tx = new AffineTransform(); tx.translate(translateX, translateY); tx.scale(scale, scale); Graphics2D ourGraphics = (Graphics2D) g; ourGraphics.setColor(Color.WHITE); ourGraphics.fillRect(0, 0, getWidth(), getHeight()); ourGraphics.setTransform(tx); ourGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); ourGraphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); ourGraphics.setColor(Color.BLACK); ourGraphics.drawRect(50, 50, 50, 50); ourGraphics.fillOval(100, 100, 100, 100); ourGraphics.drawString("Test Affine Transform", 50, 30); g.setColor(Color.black); g.drawString("ES" , xOffset, 10); g.drawString("SES", xOffset+30,10); g.drawString("BBE", xOffset+60,10); g.drawString("UAS",xOffset+90,10); g.drawString("ESR", xOffset+120,10); g.drawString("SESR", xOffset+160,10); g.drawString("BBER" , xOffset+200,10); g.drawString("SUSPECT",xOffset+240,10); g.drawString("TIME-ELAPSED",xOffset+310,10); g.setColor(plotColor1); g.fillRect(xOffset+5, 15, 12, 8); g.setColor(plotColor2); g.fillRect(xOffset+35, 15, 12, 8); g.setColor(plotColor3); g.fillRect(xOffset+65, 15, 12, 8); g.setColor(plotColor4); g.fillRect(xOffset+95, 15, 12, 8); g.setColor(plotColor5); g.fillRect(xOffset+125, 15, 12, 8); g.setColor(plotColor6); g.fillRect(xOffset+170, 15, 12, 8); g.setColor(plotColor7); g.fillRect(xOffset+210, 15, 12, 8); g.setColor(plotColor8); g.fillRect(xOffset+260, 15, 12, 8); g.setColor(plotColor9); g.fillRect(xOffset+340, 15, 12, 8); /*<Bugzilla><1903><07-Dec-2009><RR><END>*/ g.setColor(Color.black); /*Dram Graph boarder */ g.drawRect(xOffset,yOffset,SIZE_X,sizeY); g.drawRect(xOffset-1,yOffset-1,SIZE_X+2,sizeY+2); /*Plot X axis*/ int max_x_marks = 8; int temp = 1,cnt_graph = 0; int float_temp,float_temp2; /*max 8 plots on x axis*/ for(int x=max_x_marks; x>0; x--) { float_temp = (int)((MAX_NUM_INTERVELL_PER_DAY*duration)/max_x_marks)*((max_x_marks+1)-x); float_temp2 = SIZE_X-(60*cnt_graph); g.drawString(String.valueOf(float_temp),(float_temp2-20) ,SIZE_Y+yOffset+35); cnt_graph++; } /*Plot Y1 AXIS*/ temp = Y1_MAX_VALUE; for(int x = 0; x <= SIZE_Y; x+= 25) { g.drawString(String.valueOf(temp), 25, x + yOffset+10); temp -= (Y1_MAX_VALUE - 0)/10; } temp = 1000; /*Plot Y2 AXIS*/ int index_log = 1; for(int x = 0; x <= SIZE_Y1; x+= 80) { if(x== 240) index_log--; if(temp>=1) { g.drawString(String.valueOf(temp), 550, x+yOffset+8-index_log); g.drawLine(530,x+yOffset+5-index_log, 540, x+yOffset+5-index_log); } temp = temp/10; } Font thisFont = new Font("Times New Roman", Font.BOLD, 14); g.setFont(thisFont); g.drawString("Y2", 550, 160); g.drawString("Y1",5, 160); // super.paint(g); } } private static class TranslateHandler implements MouseListener, MouseMotionListener { private int lastOffsetX; private int lastOffsetY; public void mousePressed(MouseEvent e) { // capture starting point lastOffsetX = e.getX(); lastOffsetY = e.getY(); } public void mouseDragged(MouseEvent e) { // new x and y are defined by current mouse location subtracted // by previously processed mouse location int newX = e.getX() - lastOffsetX; int newY = e.getY() - lastOffsetY; // increment last offset to last processed by drag event. lastOffsetX += newX; lastOffsetY += newY; // update the canvas locations canvas.translateX += newX; canvas.translateY += newY; // schedule a repaint. canvas.repaint(); } public void mouseClicked(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseMoved(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} } private static class ScaleHandler implements MouseWheelListener { public void mouseWheelMoved(MouseWheelEvent e) { if(e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { // make it a reasonable amount of zoom // .1 gives a nice slow transition canvas.scale += (.1 * e.getWheelRotation()); // don't cross negative threshold. // also, setting scale to 0 has bad effects canvas.scale = Math.max(0.00001, canvas.scale); canvas.repaint(); } } } }Last edited by Norm; 08-03-2012 at 05:41 PM. Reason: Fixed ending code tag
- 08-03-2012, 06:52 PM #14
Re: How to convert java standalone application into applet
You should post this question on:
Java 2D or
AWT / Swing
Not related to applets.If you don't understand my response, don't ignore it, ask a question.
- 08-04-2012, 12:08 AM #15
Re: How to convert java standalone application into applet
Reposted in AWT/Swing: Zooming in graph using awt/swing
db
THREAD CLOSEDWhy do they call it rush hour when nothing moves? - Robin Williams
Similar Threads
-
How to develop a standalone application using java
By santhoshkeleti in forum New To JavaReplies: 2Last Post: 11-15-2011, 06:21 PM -
developing a standalone application using java
By santhoshkeleti in forum New To JavaReplies: 1Last Post: 11-15-2011, 06:18 PM -
How to start with JBossCache for Standalone and web based java application?
By haresh_amin in forum Advanced JavaReplies: 0Last Post: 02-03-2011, 04:36 AM -
java standalone to applet
By Nikohw in forum Java AppletsReplies: 1Last Post: 09-15-2009, 09:36 AM -
[SOLVED] License management for a Standalone java application?
By kzvi.kzvi.1 in forum Advanced JavaReplies: 4Last Post: 04-23-2009, 09:54 PM


1Likes
LinkBack URL
About LinkBacks


Bookmarks