Drawing 2d graphics

Sorry, does anybody know the most convenient way to draw graphics? f.e to draw graphic just on two vectors of points X and Y. Rrd4J is not enough good because rrd works with time.

To whom it may be interest.
This is a small example to draw a chart having "values on X" and "values on Y" :-) using JFreeChart
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import junit.framework.TestCase;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class SimpleChartTest extends TestCase {
     private XYSeriesCollection createDataset() {
          XYSeriesCollection result = new XYSeriesCollection();
          XYSeries s3 = new XYSeries("P", true, false);
          s3.add(0, 2.355450986);
          s3.add(0.5, 2.799548641);
          s3.add(1.5, 3.614688072);
          s3.add(11.5, 8.283364855);
          s3.add(12.5, 8.534275028);
          s3.add(13.5, 8.762648582);
          s3.add(14.5, 8.971407287);
          s3.add(15.5, 9.163180317);
          s3.add(16.5, 9.340328068);
          s3.add(17.5, 9.504964014);
          s3.add(19.5, 9.804039109);
          s3.add(20.5, 9.941644878);
          result.addSeries(s3);
          return result;
     private JFreeChart createChart(XYDataset dataset) {
          JFreeChart chart = ChartFactory.createXYLineChart(null,
                    "Value on X", "Value on Y", dataset, PlotOrientation.VERTICAL, true,
                    true, false);
          TextTitle t1 = new TextTitle("Title1", new Font(
                    "SansSerif", Font.BOLD, 14));
          TextTitle t2 = new TextTitle(
                    "Title2",
                    new Font("SansSerif", Font.PLAIN, 11));
          chart.addSubtitle(t1);
          chart.addSubtitle(t2);
          XYPlot plot = chart.getXYPlot();
          NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
          domainAxis.setUpperMargin(0.12);
          domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
          NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
          rangeAxis.setAutoRangeIncludesZero(false);
          return chart;
     public void test() throws IOException {
          XYSeriesCollection dataset = createDataset();
          JFreeChart chart = createChart(dataset);
          BufferedImage image = chart.createBufferedImage(360, 500);
          File file = new File("test-data/charts/newimage.png");
ImageIO.write(image, "png", file);
}

Similar Messages

  • Drawing 2D graphics with no frame or no panel ?

    Hi,
    I would like to know if it is possible to draw 2D graphics directly over the OS(windows2002) ? like drawing a rectangle over the desktop without any JPanel or JFrame.
    cheers,
    sletourne

    It is possible, I've done it ;-)
    import java.awt.*;
    import java.awt.event.*;
    public class JustSomething implements WindowListener
         public static void main(String args[])
              new JustSomething();
         public JustSomething()
              Frame winf = new Frame();
              winf.setLocation(2000,2000);
              winf.add(new java.awt.Label("If you see this you have a mighty big screen"));
              Window win = new Window(winf);          
              win.setSize(width,height);
              winf.addWindowListener(this);
         public void windowOpened(WindowEvent windowevent){}
         public void windowClosing(WindowEvent windowevent){}
         public void windowClosed(WindowEvent windowevent){}
         public void windowIconified(WindowEvent windowevent){}
         public void windowDeiconified(WindowEvent windowevent){}
         public void windowActivated(WindowEvent windowevent){}
         public void windowDeactivated(WindowEvent windowevent){}

  • Drawing a Graphics object on a Graphics object

    Is there anyway to draw a Graphics object on another Graphics object? I'm trying to show 2 screens, side by side, on a Canvas and I'm trying to cheat a little :-P Basically, I want to take half of one screen and half of another and put them on top of each other to form one screen.
    OR is there a way to turn a Graphics object into an Image object?

    I'm not sure if this is what you're after, but you can
    - create an offscreen image using "createImage(int width, int height)" method of a Component , then
    - obtain the graphics context of the offscreen image using "getGraphics()",
    - you can then draw onto the offscreen image using the graphics context.
    hope that helps. =)

  • Can somebody help me out? I need a Corel Draw (.cdr) graphic converted to Illustrator

    I'm trying to get a logo from brandsoftheworld.com but the one I want is in .CDR. I don't have Corel Draw (who does anymore) but I see that Illustrator 6 can open it. Unfortunately, I'm still on CS5.5. Can somebody help me out?

    Send it to me. I'll save it as an EPS file for you.
    Bob AT theindesignguy DOT com
    TwitchOSX <mailto:[email protected]>
    Thursday, January 24, 2013 7:11 PM
    >
          Can somebody help me out? I need a Corel Draw (.cdr) graphic
          converted to Illustrator
    created by TwitchOSX <http://forums.adobe.com/people/TwitchOSX> in
    /InDesign/ - View the full discussion
    <http://forums.adobe.com/message/5020999#5020999

  • Inability to draw simple graphics in Java properly (threads and JFrame)

    I am trying to use a thread to continually draw randomly positioned and randomly sized squares in the middle of a JFrame window. I have got 'something' working with the following code, however when run, the actual window doesn't come up properly. If I resize the window it does, and I get the result I wanted, but when the window is first opened it does not fully draw itself on screen. Can anybody help here? I am a bit of a novice when it comes to Java
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class TestDraw extends JFrame implements Runnable {
    //DECLARE VARIABLES
         private JLabel lblText;
         private JButton btnBegin;
         private JPanel contentPane;
         private int CoordX, CoordY,SizeX, SizeY, Colour;     // Co'ords for drawing the squares
         Random random = new Random();                              // Random numbers (for square dimensions and colours)
         int n_1 = 450, n_2 = 130, n_3 = 100, n_4 = 4;          // The different ranges of randoms I require
         Thread squares = new Thread(this);                         // Implements a new thread
    //END OF DECLARE VARIABLES
    // CALLS INITIAL PROCEDURE, SETS VISIBLE ETC
         public TestDraw() {
              super();
              initializeComponent();
              this.setVisible(true);
    // INITIALISATION PROCEDURE CALL
         private void initializeComponent() {
              lblText = new JLabel();
              btnBegin = new JButton();
              contentPane = (JPanel)this.getContentPane();
              // lblText
              lblText.setText("This should draw squares on screen...");
              // btnBegin
              btnBegin.setText("Start");
              btnBegin.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent e) {
                        btnBegin_actionPerformed(e);
              // contentPane
              contentPane.setLayout(null);
              addComponent(contentPane, lblText, 10,300,364,18);
              addComponent(contentPane, btnBegin, 144,10,101,28);
              // TestDraw
              this.setTitle("TestDraw Program for CM0246");
              this.setLocation(new Point(0, 0));
              this.setSize(new Dimension(390, 350));
    // POSITION COMPONENTS ON SCREEN
         private void addComponent(Container container,Component c,int x,int y,int width,int height)     {
              c.setBounds(x,y,width,height);
              container.add(c);
    // EVENT HANDLING PROCEDURES
         private void btnBegin_actionPerformed(ActionEvent e) {
              System.out.println("\nAction Event from btnBegin called...");
              squares.start(); //STARTS THE SQUARES DRAWING THREAD (Draws random squares on screen)
    // THE MAIN METHOD (STARTS THE PROGRAM)
         public static void main(String[] args) {
              TestDraw bobdole = new TestDraw();
    // THE SQUARE DRAWINGS THREAD (SHOULD DRAW RANDOM SIZED AND COLOURED SQUARES IN RANDOM PLACES)
         public void run() {
              System.out.println("Thread running if this prints");
                   while(true) {
                        int int_1 = random.nextInt(n_1);     // chooses random int for X co'ord
                        int int_2 = random.nextInt(n_2)+70;     // chooses random int for Y co'ord
                        int int_3 = random.nextInt(n_3)+10;     // chooses random int for X dimension
                        int int_4 = random.nextInt(n_3)+10;     // chooses random int for Y dimension
                        CoordX = int_1;
                        CoordY = int_2;
                        SizeX  = int_3;
                        SizeY  = int_4;
                        repaint();
                        try {
                             squares.sleep(500);
                        catch (InterruptedException e) {
                             System.out.println(e);
    // THE PAINT METHOD ATTATCHED TO THE SQUARES THREAD
         public void paint( Graphics g ) {
              System.out.print("Colour" + Colour);
              g.setColor(Color.blue);
              g.fillRect(CoordX, CoordY, SizeX, SizeY);
    // END OF PROGRAM

    I don't see any problem when I run the program but.. In general you shouldn't paint directly on a frame by overloading the paint method. You should rather create a custom component on which you draw.
    But if you do overload paint, make sure you call super.paint before doing anything else.
    More information in this tutorial: http://java.sun.com/docs/books/tutorial/uiswing/painting/index.html

  • Drawing with graphics

    If I draw a rounded rectangle from top to bottom, the corners are nicely rounded. If I draw the rectangle from bottom to top the entire shape is rounded instead of just the corners. How can I draw from bottom to top and still round just the corners?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"   creationComplete="init()">
        <mx:Script>
            <![CDATA[
                private function init():void{
                    canvas.graphics.beginFill(0xffff00);
                    canvas.graphics.drawRoundRect(300,300,50,200, 20, 20);
                    canvas.graphics.drawRoundRect(600,500,50,-200, 20, 20);
            ]]>
        </mx:Script>
    <mx:Canvas id="canvas"    />
    </mx:Application>

    If I draw a rounded rectangle from top to bottom, the corners are nicely rounded. If I draw the rectangle from bottom to top the entire shape is rounded instead of just the corners. How can I draw from bottom to top and still round just the corners?
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"   creationComplete="init()">
        <mx:Script>
            <![CDATA[
                private function init():void{
                    canvas.graphics.beginFill(0xffff00);
                    canvas.graphics.drawRoundRect(300,300,50,200, 20, 20);
                    canvas.graphics.drawRoundRect(600,500,50,-200, 20, 20);
            ]]>
        </mx:Script>
    <mx:Canvas id="canvas"    />
    </mx:Application>

  • Appleworks6 (drawing - text & graphics) to be converted - how?

    I have a lot of mathematics worksheets, produced on Appleworks6 (on the drawing package with text and graphics) over the years. The new OS will not support Rosetta, I understand, and so I need to transfer (translate?) all the worksheets into a more modern format, available to both Mac and PC users. How do I do this and what applications are now available which will be suitable? If I try Word:mac (11.6.3) it tells me the Appleworks6 drawing document is not the right file type.

    If it were an AW6 text document with inserted graphics, then Pages would probably open it.
    However, as a drawing document with text added that may not work. It is possible that Keynote might be able to open it.
    Edit - - nope - just tried it with Keyboate, won't do it.
    Just played with AW6 a bit. If these documents are static docs, meaning ones which do not need to be changed or otherwise addressed except viewed, there's other choices. One I tried just now in AW6, ws to do a Save As and change the format to JPEG.
    This resulted in a document that should be openable by most anyone. In OS X, it opens in Preview automatically, but should be able to be opened in any app that can open JPEG files.
    In Pages it got a bit trickier - Pages would not open it directly, not even via Open in File menu. But, when I treated it as a regular JPEG it worked: I opened a blank text doc in Pages, then drag-and-dropped the JPEG file into it. That worked - gave me a Pages doc with an inserted image of the original AW6 graphics file.

  • Drawing 2D Graphics in the center of a JPanel

    Hi,
    Below is my GUI. The basic idea is, I want this to create a neat UI on any machine with any monitor resolution settings. Because I dont really know what will be the resolution of the target machine, I do not perform a setPreferred size on any component. I have several problems here.
    1. My DiagramPanel.paintComponent method relies on the Panel's preferred size to draw a rectangle in the center of the panel. When a panel is layed out using BorderLayout, it expands it to fit the space. So is there some method I can use to know, what space the component panel is occupying (its dimension) ?
    2. Also, when the frame is maximized or resized, the DiagramPanel's dimension changes. So I want to be able to redraw the diagram in the new center position. How can I do this ?
    4. I am using the Frame size to be the screen dimension and set it to be maximized. So when I try to restore the window, it takes up the whole screen even the space including the windows taskbar. Is there someway to get the screen dimension leaving out the space for the taskbar ?
    3. I dont set the DividerLocation of the contentPane because, I want it to be set automatically based on the contents of the leftPanel. But when i print out the dividerLocation after creating the UI, it prints -1. How can I get the current divider location then ?
    import java.awt.BorderLayout;
    import java.awt.Button;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.LayoutManager;
    import java.awt.Toolkit;
    import java.awt.Graphics;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JSplitPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    @SuppressWarnings("serial")
    public class MainFrame extends JFrame {
    public MainFrame() {
    createAndShowGUI();
    private void createAndShowGUI() {
    initMainFrame();
    initMenus();
    initPanels();
    initContentPane();
    setVisible(true);
    System.out.println("Divider location "+ contentPane.getDividerLocation());
    private void initMainFrame() {
    setTitle("Main Frame");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setState(JFrame.NORMAL);
    //GETS SCREEN SIZE
    Dimension screen_Dimension = Toolkit.getDefaultToolkit().getScreenSize();
    setSize(screen_Dimension.width, screen_Dimension.height);
    setExtendedState(MAXIMIZED_BOTH);
    private void initContentPane() {
    getContentPane().add(contentPane);
    contentPane.setEnabled(false); / *prevent the divider location from being moved* /
    contentPane.setLeftComponent(leftpanel);
    contentPane.setRightComponent(rightpanel);
    contentPane.setOpaque(true);
    private void initMenus() {
    exitMenu.setActionCommand(EXIT_COMMAND);
    file.add(exitMenu);
    menub.add(file);
    setJMenuBar(menub);
    private void initPanels() {
    initLeftPanel();
    initRightPanel();
    private void initLeftPanel() {
    leftpanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    leftpanel.add(new Button("Click"));
    private void initRightPanel() {
    LayoutManager border = new BorderLayout();
    rightTab.setLayout(border);
    scrollingDiagram = new JScrollPane(diagramPanel);
    diagramDescriptionPanel.setLayout(new BorderLayout());
    diagramDescriptionPanel.add(diagDescTextArea, BorderLayout.CENTER);
    rightTab.add(scrollingDiagram, BorderLayout.CENTER);
    rightTab.add(diagramDescriptionPanel, BorderLayout.SOUTH);
    rightpanel.addTab("Right Tab", rightTab);
    public static void main(String args[]) {
    try {
    new MainFrame();
    } catch (Exception e) {
    e.printStackTrace();
    System.exit(0);
    private JSplitPane contentPane = new JSplitPane();
    private JMenuBar menub = new JMenuBar();
    private JMenu file = new JMenu("File");
    private JMenuItem exitMenu = new JMenuItem("Exit");
    private JPanel leftpanel = new JPanel();
    private JTabbedPane rightpanel = new JTabbedPane();
    private JPanel rightTab = new JPanel();
    private JScrollPane scrollingDiagram;
    private DiagramPanel diagramPanel = new DiagramPanel();
    private JPanel diagramDescriptionPanel = new JPanel();
    private JTextArea diagDescTextArea = new JTextArea(18, 45);
    public static final String EXIT_COMMAND = "Exit";
    @SuppressWarnings("serial")
    class DiagramPanel extends JPanel{
    public static int RECT_WIDTH = 100;
    public static int RECT_HEIGHT = 75;
    public void paintComponent(Graphics g) {
    super.paintComponents(g);
    Coordinates centerOfPanel = getCenterCoordinates();
    g.drawRoundRect(centerOfPanel.x, centerOfPanel.y, RECT_WIDTH, RECT_HEIGHT, 10, 10);
    public Coordinates getCenterCoordinates() {
    Dimension panelDimension = getPreferredSize();
    int x = (panelDimension.width - RECT_WIDTH) / 2;
    int y = (panelDimension.width - RECT_HEIGHT) / 2;
    return new Coordinates(x,y);
    class Coordinates {
    int x;
    int y;
    Coordinates(int x, int y) {
    this.x = x;
    this.y = y;

    Hi,
    The getSize worked perfectly for me. But what I tried doing now is that, instead of just the simple centering of the rectangle, i did this
    1. When the dimension of the rectangle is smaller than the Panel.getSize(), do centering as usual
    2. else when the rectangle is bigger, say because its width was longer than Panel.getSize().getWidth(), I center the rectangle only on its Height, and set the preferred size of the Panel to (rectangle.getWidth(), panel.getSize().getHeight()). And I call revalidate, so that the scrollbars appear.
    Problem im running into now is that, once I do a setPreferredSize, everytime I use a getSize later on, i always get the same size. But what I want to see is that, when the rectangle can fit in the panel, i want it centered without any scrollbars, but when it cannot fit on the width, i want it to appear centered on height, but have a horizontal scroll bar.
    I'd be really grateful, if you could help me with this.
    Here is the code
    public void paintComponent(Graphics g) {
              super.paintComponents(g);
              Coordinates centerOfPanel = getCenterCoordinates();
              g.drawRoundRect(centerOfPanel.x, centerOfPanel.y, RECT_WIDTH, RECT_HEIGHT, 10, 10);
              //preferredSize might have changed, call revalidate
              revalidate();
    public static final int PANEL_MARGIN = 50;
    public Coordinates getCenterCoordinates() {
              setPreferredSize(null);
              Dimension panelDimension = getSize();
              Dimension myPreferredSize = new Dimension();
              if (panelDimension.width > RECT_WIDTH)
                   myPreferredSize.width = panelDimension.width;
              else
                   myPreferredSize.width = RECT_WIDTH + 2 * PANEL_MARGIN; // MARGIN on left end and right end
              if (panelDimension.height > RECT_HEIGHT)
                   myPreferredSize.height = panelDimension.height;
              else
                   myPreferredSize.height = RECT_HEIGHT + 2 * PANEL_MARGIN; // MARGIN on top and bottom
              System.out.println("Panel size is " + getSize());
              setPreferredSize(myPreferredSize);
              System.out.println("Preferred size is " + myPreferredSize);
              //center of the panel.
              int x = (myPreferredSize.width - RECT_WIDTH) / 2;
              int y = (myPreferredSize.height - RECT_HEIGHT) / 2;
              return new Coordinates(x,y);
         }

  • Help in drawing graphics.

    Hi friends,
    I'm newbie in drawing graphics with Java, and I need some help in a specific part of my program.
    What I want to do is to draw a waveform of a sound file. That waveform is built based on the amplitude of each sound sample. So I have a big vector full of those amplitudes. Now what I need to do is plot each point on the screen. The x coordinate of the point will be its time position in the time axis. The y coordinate of the point will be the amplitude value. Ok... Now I have a lot of doubts...
    1 - can someone give me a simple example on how to plot points in a java app? I know I have to extend a JPainel class, but I don't know much about those paint, and repaint methods. It's all weird to me. I already searched through the tutorial and the web, but I couldn't see a simple, good example. Can someone hand me this?
    2 - Once I know how to draw those graphics, I need to find a way to put a button, or anything like that, in my app, so the user can press that button to see to next part of the waveform, since the wave is BIG, and doesn't fit entirely on the screen. Is this button idea ok? Can I use some sort of SCROLL on it, would it be better?
    Well... I'm trying to learn it all. ANY help will be appreciated, ANY good link, little hint, first step, anything.
    Thanks for all, in advance.
    Leonardo
    (Brazil)

    This will lead you, in this sample you have a panel and a button,
    every click will fill a vector with random 700 points and draw them on the panel,
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class Wave extends Frame implements ActionListener
         WPanel   pan    = new WPanel();
         Vector   points = new Vector();
         Button   go     = new Button("Go");
         Panel    cont   = new Panel();
    public Wave()
         super();
         setBounds(6,6,700,400);     
         addWindowListener(new WindowAdapter()
        {     public void windowClosing(WindowEvent ev)
                   dispose();     
                   System.exit(0);
         add("Center",pan);
         go.addActionListener(this);
         cont.add(go);
         add("South",cont);
         setVisible(true);
    public void actionPerformed(ActionEvent a)
         points.removeAllElements();
         for (int j=0; j < 700; j++)
              int y = (int)(Math.random()*350);
              points.add(new Point(j,y+1));
         pan.draw(points);
    public class WPanel extends Panel
         Vector   points;
    public WPanel()
         setBackground(Color.pink);
    public void draw(Vector points)
         this.points = points;
         repaint();
    public void paint(Graphics g)
         super.paint(g);
         if (points == null) return;
         for (int j=1; j < points.size(); j++)
              Point p1 = (Point)points.get(j-1);
              Point p2 = (Point)points.get(j);
              g.drawLine(p1.x,p1.y,p2.x,p2.y);
    public static void main (String[] args)
         new Wave();  
    Noah

  • Drawing graphic component using parsed file

    hi,
    I have a problem in drawing the graphic components like rectangle,oval etc. I need to draw them on a panel after selecting a xml file from menu,parse it first, based on the contents of the parsed file the dimentions of the component should change.
    however i am able to parse the file and save the parsed contents in a separate file, but unable to draw components using its contents

    this is the module given to me where i am supposed to
    draw the graphic components using the contents of a
    xml file. I was told to parse the xml file to get
    some values that would represent parameters like
    packet size, length etc.. and using these values
    draw a data packet representation. But prob here is
    the i am able to parse file but not pass its values
    simultaneously to draw image on the panel
    immediately after parsing. i am storin the contents
    in the text format.
    ya i have good knowlege of swings,IO and awt...Parse the XML file filling a model that allows listeners (Observer/Observable is one approach). When the parsing is complete fire an event to indicate that the model has changed. Have your GUI listen to the model and when it receive the 'changed' event it updates it's display according to the content of the model.

  • Export graphic for use in Premiere Pro Cs4

    Hey everyone, I have made some wiring diagrams in AI CS4 and need to have them apear in a DVD, I have tried several cominations and they are not clear on the video.  My settings are RGB, DV NTSC Widescreen, have exported for Web and Devises and in Tiff & Targa 72 & 300 DPI.  The diagram has text that looks fine in all the stills but in Premiere and the exported video the images look like a poor photo copy.  Thought I'd start here before asking in PPro.  Any thoughts would be appreciated.

    Mmh, differences between versions aside, you are pretty much getting what you are asking. Any compressed format will have a hard time with perependicular lines and lots of high fequency detail (text, the coil spirals). There's really no way to avoid that otehr than to draw thr graphic differently, i.e. not use straight lines and a different way of presenting the text callouts. Also, you could massively improve perception by having the graphic move with a simple slow pan. the motion will lead to a more favorable distribution of the pixels across the scanlines, as the content changes every frame and in addition, motion blur will help to reduce flicker. Lastly, give the graphic some finesse by perhaps making the lines white and adding a dark outer glow to separate them from the background. these blended areas also help to reduce artifacts that appear with harsh transitions on straight lines. If it's an option , you might even want to use color for the + and - cabling (usually blue and red). As Wade suggested, you might try rendering to a different spec, but depending on what your intended final output is, this may not help at all, so working a bit on the graphic might pay off more.
    Mylenium

  • How to make Graphics a separate thread.

    Hi all!
    I am performing dense 2D Delaunay triangulation on the Java Graphics context. I don't want to add any "sleeps" there in my code, so my app eats about 95-98% of CPU resources. I am becoming unable to normally use any components (i.e. buttons, combos etc) in my app because they are stuck and will responde after 10 secs or more. I tried to get out and did the things specified below.
    Assuming I have the following code:
    import javax.swing.*;
    import java.awt.*;
    public class Test extends JPanel {
    int count = 0;
    int loop = 100;
    Graphics g0 = null;
    Thread thr = null;
    public void paint(Graphics g)
         super.paint(g);
         g0 = g;     
          thr = new Thread(new Runnable() {
              public void run() {
               while (loop < 600) {
                    * Really I am doing a lot of things here,
                    * so there is no problem with such a blind loop causing 100%CPU usage
                    * or "too much threads" errors
                   g0.drawString(""+(count++), loop, 200);
                   if(count>9)count=1;
                    * Uncomment this after one try.
                    * Your JVM will crash instantly or a little later
                    * depending on the sleep value below.
                   //g0.drawLine(loop-10,100, loop-10, 200);
                   /*Uncomment this for test and manipulate with the sleep time in range 1..500*/
                   //try {Thread.sleep(500);}catch (InterruptedException ex) {}
                   loop+=10;               
                   repaint();               
               loop = 100;
          thr.setPriority(Thread.MAX_PRIORITY);
          thr.start();
    public static void main(String[] args) {
         JFrame fr = new JFrame();
         Test test1 = new Test();
         test1.setDoubleBuffered(true);
         fr.setSize(700,500);
         fr.getContentPane().add(test1);     
         fr.setLocation(70,70);
         fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         fr.show();     
    }After the crash my JVM(1.4.2_01-b06 on WinXP) says me "good bye" with this message or a similar long one with the whole dll list:
    Another exception has been detected while we were handling last error.
    Dumping information about last error:
    ERROR REPORT FILE = (N/A)
    PC = 0x02eb7516
    SIGNAL = -1073741819
    FUNCTION NAME = Java_sun_print_Win32PrintJob_endPrintRawData
    OFFSET = 0x13E2
    LIBRARY NAME = C:\JBuilderX\jdk1.4\jre\bin\awt.dll
    Please check ERROR REPORT FILE for further information, if there is any.
    Good bye.
    An unexpected exception has been detected in native code outside the VM.
    Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x2EB7516
    Function=Java_sun_print_Win32PrintJob_endPrintRawData+0x13E2
    Library=C:\JBuilderX\jdk1.4\jre\bin\awt.dll
    Current Java thread:
    at sun.awt.windows.Win32DDRenderer.doDrawLineDD(Native Method)
    at sun.awt.windows.Win32DDRenderer.clipAndDrawLine(Win32DDRenderer.java:76)
    at sun.awt.windows.Win32DDRenderer.drawLine(Win32DDRenderer.java:126)
    As I described, the crash happens only when I use drawLine()/draw()/drawRect() or another standard method of Graphics/Graphics2D context except drawString() method.
    Did you try to solve a problem like mine is? Can you provide a RIGHT(I know that mine is simple, wrong and dummy ) alternative for separation of Graphics thread from the main one?
    Thank you guys for at least reading my post
    Waiting for a shameful reply to this message!
    Goodbye!

    Don't draw the graphics in the AWT event queue thread.
    Draw them in the main thread and repaint the
    component that displays them as they become
    available. The basics of a component like that are
    shown in message 15 this thread:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=55
    795&start=15&range=15&hilite=false&q=
    In the same thread under the reply #19 u wrote:
    The problem with drawing in the paintComponent() method is that it executes in the GUI thread and this >slows down the rest of the GUI. Many of my GUI apps involve mathematical transformations to images >which take too long to run inside paintComponent().I have the same problem though I am overriding the paint() method, i.e. my GUI thread is being hung even I use the paint() method. Forget about the code above, so there is no thread spawning, no MAX_PRIORITY and no paint()/repaint() recursivity. Did you fixed that problem by such a double buffering like action you specified in the reply #15?
    Thx!

  • How to use a Graphics Object in a JSP?

    Hello, I do not know if this is a good or a silly question. Can anyone tell me if we can use a Graphics object in a JSP. For example to draw a line or other graphics, i am planning to use the JSP. Any help is much appreciated.
    Regards,
    Navin Pathuru.

    Hi Rob or Jennifer, could you pour some light here.
    I have not done a lot of research for this, but what i want to do is below the polygon i would like to display another image object like a chart... is it possible? If so how to do it? Any help is much appreciated.
    here is the code:
    <%
    // Create image
    int width=200, height=200;
    BufferedImage image = new BufferedImage(width,
    height, BufferedImage.TYPE_INT_RGB);
    // Get drawing context
    Graphics g = image.getGraphics();
    // Fill background
    g.setColor(Color.white);
    g.fillRect(0, 0, width, height);
    // Create random polygon
    Polygon poly = new Polygon();
    Random random = new Random();
    for (int i=0; i < 5; i++) {
    poly.addPoint(random.nextInt(width),
    random.nextInt(height));
    // Fill polygon
    g.setColor(Color.cyan);
    g.fillPolygon(poly);
    // Dispose context
    g.dispose();
    // Send back image
    ServletOutputStream sos = response.getOutputStream();
    JPEGImageEncoder encoder =
    JPEGCodec.createJPEGEncoder(sos);
    encoder.encode(image);
    %>
    Regards,
    Navin Pathuru

  • Line Drawing Script on Stage doesn't work in MovieClip?

    I have a little snippet of code that allows the user to create a line with the mouse, and clears the line if they end up touching the hitbox with the mouse, while they're drawing the line. It works fine when it's just thrown onto the main timeline. However, when I try to encapsulate it within a movie clip, it suddenly doesn't work. At all. Are there any suggestions as to why this is happening? Here's the code.
    function(){return A.apply(null,[this].concat($A(arguments)))}
    var drawing:Boolean;
    var my_line:MovieClip = new MovieClip();
    this.addChild(my_line);
    drawing = false;//to start with
    stage.addEventListener(MouseEvent.MOUSE_DOWN, startDrawing);
    stage.addEventListener(MouseEvent.MOUSE_MOVE, draw);
    stage.addEventListener(MouseEvent.MOUSE_UP, stopDrawing);
    function startDrawing(event:MouseEvent):void
    //move to the correct starting position for drawing
    my_line.graphics.lineStyle(3,0xFF0000);
    my_line.graphics.moveTo( mouseX, mouseY);
    if (drawBox.hitTestPoint(mouseX,mouseY,true))
      drawing = true;
    function draw(event:MouseEvent)
    if (drawing)
      my_line.graphics.lineTo(mouseX,mouseY);
      if (oneHitBox.hitTestPoint(mouseX,mouseY,true))
       my_line.graphics.clear();//remove line
    function stopDrawing(event:MouseEvent)
    drawing = false;
    Thanks for any help you can offer!

    Oh! Haha, sorry, brainfart. That is all of the code that I use in that particular frame, where I want the user to be able to draw within the confines of the box. The only other code I use are for the drag and drop boxes, meant to be dropped onto a particular area. Those are working just fine, but if you want to see that code too, then:
    function(){return A.apply(null,[this].concat($A(arguments)))}
    /* Stop at This Frame
    The Flash timeline will stop/pause at the frame where you insert this code.
    Can also be used to stop/pause the timeline of movieclips.
    stop();
    /* Drag and Drop
    Makes the specified symbol instance moveable with drag and drop.
    lunchOff.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag);
    function fl_ClickToDrag(event:MouseEvent):void
    lunchOff.startDrag();
    stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop);
    function fl_ReleaseToDrop(event:MouseEvent):void
    lunchOff.stopDrag();
    if (lunchOff.hitTestObject(dropBoxTwo))
      if (offDuty.hitTestObject(dropBoxThree) && onDuty.hitTestObject(dropBoxOne) && lunchOff.hitTestObject(dropBoxTwo))
       gotoAndStop(16);
       stage.focus = aBox;
    else
      lunchOff.x = -548.95;
      lunchOff.y = -306.15;
    /* Drag and Drop
    Makes the specified symbol instance moveable with drag and drop.
    offDuty.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_2);
    function fl_ClickToDrag_2(event:MouseEvent):void
    offDuty.startDrag();
    stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_2);
    function fl_ReleaseToDrop_2(event:MouseEvent):void
    offDuty.stopDrag();
    if (offDuty.hitTestObject(dropBoxThree))
      if (offDuty.hitTestObject(dropBoxThree) && onDuty.hitTestObject(dropBoxOne) && lunchOff.hitTestObject(dropBoxTwo))
       gotoAndStop(16);
       stage.focus = aBox;;
    else
      offDuty.x = -557.0;
      offDuty.y = -155.95;
    /* Drag and Drop
    Makes the specified symbol instance moveable with drag and drop.
    onDuty.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_3);
    function fl_ClickToDrag_3(event:MouseEvent):void
    onDuty.startDrag();
    stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_3);
    function fl_ReleaseToDrop_3(event:MouseEvent):void
    onDuty.stopDrag();
    if (onDuty.hitTestObject(dropBoxOne))
      if (offDuty.hitTestObject(dropBoxThree) && lunchOff.hitTestObject(dropBoxTwo))
       gotoAndStop(16);
       stage.focus = aBox;
    else
      onDuty.x = -539.00;
      onDuty.y = 39.45;

  • Cannot resolve symbol class graphics

    does anyone know what the error
    cannot resolve symbol class graphics means?
    with this code i can't seem to call the graphics method to draw the line....any reason why?
    import javax.swing.*;
    import java.*;
    public class LineDraw extends JFrame {
        public static void main(String[] args) {
            LineDraw ld = new LineDraw();
            ld.setSize(500,500);
            ld.setVisible(true);
            ld.enterVariables();
        public void init(){
        private int x1;
        private int x2;
        private int y1;
        private int y2;
        public void paint(Graphics g) {
            g.GetGraphics(g);
            super.paintComponent(g);
            g.drawLine(x1, y1, x2, y2);
        public void enterVariables() {
            x1 = Integer.parseInt(JOptionPane.showInputDialog("Enter x1:"));
            y1 = Integer.parseInt(JOptionPane.showInputDialog("Enter y1:"));
            x2 = Integer.parseInt(JOptionPane.showInputDialog("Enter x2:"));
            y2 = Integer.parseInt(JOptionPane.showInputDialog("Enter y2:"));
            repaint();
    }

    well the exact error message is ...by the way now that i think about it
    if the graphics method shoudl not be part of the JFrame class then what method would i use to draw 2D Graphics?
    --------------------Configuration: <Default>--------------------
    C:\Documents and Settings\c1s5\My Documents\LineDraw.java:21: cannot resolve symbol
    symbol : class Graphics
    location: class LineDraw
    public void paint(Graphics g)
    ^
    1 error
    Process completed.
    and the exact code is
    import javax.swing.*;
    import java.*;
    public class LineDraw extends JFrame {
        public static void main(String[] args) {
            LineDraw ld = new LineDraw();
            ld.setSize(1024,500);
            ld.setVisible(true);
            ld.enterVariables();
        private int x1;
        private int x2;
        private int y1;
        private int y2;
        public void paint(Graphics g)
            super.paintComponent(g);
            g.drawLine(x1, y1, x2, y2);
        public void enterVariables() {
            x1 = Integer.parseInt(JOptionPane.showInputDialog("Enter x1:"));
            y1 = Integer.parseInt(JOptionPane.showInputDialog("Enter y1:"));
            x2 = Integer.parseInt(JOptionPane.showInputDialog("Enter x2:"));
            y2 = Integer.parseInt(JOptionPane.showInputDialog("Enter y2:"));
            repaint();
    }

Maybe you are looking for

  • Error while running ETL for Financials_Oracle R1213.

    Hi All, I have done all installation and configuration for OBIA 7.9.6.4. I am getting following error while running ETL for Financials_Oracle R1213. =====================================================================================================

  • Passing Cookies To Portlets

    Greetings, I have implemented the ISSOIntegration interface, and in the GetSecureCookies method I am returning an array of cookie names that I want passed down to my portlets. I hit the portal with the said cookies in the headers, and I am able to ex

  • Regarding Street3 and Street 4 in Vendor Master

    hi all,        I am trying to upload Vendor Master data through LSMW. But When i am doing recording i am not getting the fields  Street3 , Street4 and Street 5. I tried in Direct Input Method also. I am not getting that fields. Please suggest any sta

  • Exact  difference between se09 and se10

    Hi all, i want to know the exact difference  between se09 and se10  . i know SE09 is the workbench transport requests transaction - here the developers can track changes to all ABAP workbench objects (dictionary, reports, module pools, etc). This is

  • Costs Involved with SAP Netweaver PI 7.1?

    Hi SAP Experts, Just wanted to ask if there are any transaction based costs for the SAP Netweaver PI 7.1?  For example, data is sent to PI -> PI sends data to 3rd party software (and vice-versa). Would there be a transaction costfor the scenario abov