Problem on drawin a graph

I'm a just beginner in Swing.I want to draw a graph on a frame.My problem is.....:in the o/p window graph is just become disable afterit came.it will reappear whwn we maximize thhe o/p window...my part of code is following:
public void paint(Graphics g) {//main graph drawing part
          super.paint(g);
          Graphics2D g2 = (Graphics2D)g;
          g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
          for(i=0;i<ss2;i++){//assigning the the values of FROM node and TO node
               pf=p[Integer.parseInt(str2[i][0])];
               pt[i]=p[Integer.parseInt(str2[i][2])];
          for(i=0;i<ss2;i++){//to print the value like a,b,c...
               xf=pf[i].x;
               yf=pf[i].y;
               xt=pt[i].x;
               yt=pt[i].y;
               xm=(xf+xt*3)/4;
               ym=((yf+yt*3)/4)-5;
               sssss=str2[i][1].charAt(0);
               g2.setColor(Color.black);
               if(xf==xt&&yf==yt){
                    g2.drawArc(xf,yf,35,20,0,360);
                    g2.drawString(Character.toString(sssss),xf+15,yf+12);
               else{
                    g2.drawLine(xf,yf,xt,yt);
                    g2.setColor(Color.black);
                    g2.drawString(Character.toString(sssss),xm,ym);
                    g2.fillOval(m,n,7,7);
          for(i=0;i<sc1;i++) {//for loop to draw the circle class to draw circles
               int _x;
               int _y;
               _x=(p[i].x-10);
               _y=(p[i].y-10);
               if(str1[i][3].equals("1")){
               g2.setColor(Color.PINK);
               g2.fillOval(_x, _y,20,20);
               x=0;y=0;
          else if(str1[i][3].equals("2")){
               g2.setColor(Color.CYAN);
               g2.fillOval(_x, y,20,20);x=0;_y=0;
          else if(str1[i][3].equals("4")){
               g2.setColor(Color.YELLOW);
               g2.fillOval(_x, y,20,20);x=0;_y=0;
          else{
               g2.setColor(Color.ORANGE);
               g2.fillOval(_x, y,20,20);x=0;_y=0;
          for(i=0;i<sc1;i++){//to put the node name like 1,2...i'll changed it to Q0,Q1,... later
               g2.setColor(Color.BLACK);
               g2.drawString(Integer.toString(i),p[i].x,p[i].y);

Comments:
If you had gone through the painting tutorial linked, you would know that custom painting is not normally performed on a JFrame. And knowing that, you would find no reason to extend JFrame.
If you had taken a look at the API you would know that JFrame doesn't have a method paintComponent.
If you had gone through the Swing tutorial linked, you would know about concurrency in Swing, and that the GUI should be launched on the EDT.
So. With the wealth of knowledge already available in the tutorials, do you really think forum members should waste their time teaching you the basics? Please go through the changed code and post back what you conclude about the differences that make it work.
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class FrameTest {
   int px, py, ox, oy;
   JFrame frame;
   JPanel panel;
   FrameTest(String title, int x1, int y1, int x2, int y2){
      frame = new JFrame(title);
      px = x1;
      py = y1;
      ox = x2;
      oy = y2;
   private void makeUI() {
      panel = new JPanel() {
         public void paintComponent(Graphics g){
            super.paintComponent(g);
            g.drawLine(px, py, ox, oy);
      frame.setContentPane(panel);
      frame.setSize(300, 300);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
   public static void main(String args[]) {
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            new FrameTest("Show", 10, 10, 100, 100).makeUI();
}db

Similar Messages

  • Problems to generate a graph using 2 views as 2 curves

    Hello everybody
    Please help me fix this problem.
    Oracle 9i Database,reports-->graph wizard
    I have 2 views in the database named FR1,FR2 and these 2 views are nothing but snapshots of data from a single table WDATA for selected data .
         The views are like this
         FR1                         FR2
         NO number(10)                    NO number(10)
         VALUE number(10)               VALUE number(10)
         Each view has 20 records of data
    I need to generate a graph for the 2 views as 2 curves in graph for analysis with NO as X axis and VALUE as Y axis.
    |.::::.
    |
    |________
    But i couldn't manage to generate them.
    When i write a query in report wizard like this
    SELECT * FROM FR1 UNION SELECT * FROM FR2
    I get 40 records but as a single view thereby not possible to generate 2 curves..In this case i get 1 curve with 40 points.
    and if I say
    SELECT * FROM FR1,FR2
    I get 400 records as cartesian product of the 2 views which makes no sense.
    Some one out there please help me..
    Is my approach correct for generating graphs?
    i'm using 9iDS and 9i DB
    thanx in advance
    regards
    Jochen

    jochen,
    you need to join the two tables but use a where clause to prevent a cartesian product.
    so the following select should work
    select a.no, a.value, b.value
    from fr1 a, fr2 b
    where a.no = b.no
    regards,
    philipp

  • Problems with express xy graph

    Hi,
    I am new to Labview. I am using Labview 8.5. I wish to create a program which reads in an excel spreadsheet and displays the data on an express xy graph. I have been able to read my excel spreadsheet into labview but cannot display a graph in my express xy graph. The express xy graph plots only one point and I do not understand why. I would be grateful if someone could please advise me on what the problem could be. The block diagram is shown below.
    Your help is very much appreciated. Thank You.
    Dibz

    To elset191: I have actually added a transpose array between the Read From Spreadsheet and the express xy graph and it now displays a full graph! Thank you. I mistakenly thought the xy graph read in the data in columns rather than rows. However, the y-axis values is a 2D array. Therefore, ideally I would like each row of this data to generate its own plot on the xy graph. Can it do this? At the moment the express xy graph looks like its only reading in the first row of y-axis 2D array. Would I be able to somehow show multiple plots on the express xy graph for each row of the data?
    To Dennis Knutson: Apologies, but i thought it would have been assumed that as you cannot read in native excel files as you said, then obviously I had converted the file if I initially stated I had read it into Labview. Also, as stated above the y-axis is actually a 2D array which is why I used the 2D array to display it. Granted, the x-axis values is a single array but no problems were incurred so I did not get around to changing it. 

  • Problems with Flash Line Graphs

    I have two problems with the new Flash Line Graphs in APEX 3.1
    1. I have created a query that returns a set number of rows. Sometimes the VALUE for a specific row might be null. When this occurs the LABEL data does not show up on the X axis. I want the LABEL data to show up no matter what. How do I accomplish this?
    2. Related to the above query. When the VALUE field is null for 3 records (or more) in a row, not only does the LABEL data for those records not display, the VALUE and LABEL data for the records that appear in the set after these 3 records also do not display. If one or even two null VALUE fields appears in a row, things are still OK. What do I need to do to get all my data to display?
    Any help would be appreciated.
    THANKS
    Raymond

    Raymond,
    For the Interactive report chart issue, could it be related to this?
    Re: Apex 3.1. Interactive Report. Questions and Problems.
    Interactive Report. Chart. Seems to be bug...
    - Christina

  • Problem with customization of graph

    Hi experts,
    I am facing some problem in customizing graphs created through Report Builder. I am having some values on x-axis like employee name (emp-code).
    e.g. Janak Nirmal (007)
    I did one thing that i m only displaying emp-code on x-axis. i.e. 007
    now i want to show user also which emp-code is bind to employee name any where in graph.
    i.e. 007=Janak Nirmal
    is this customization possible ?
    how do i include it in jsp page ? how do i customize graph x-axis.
    Is there any way to do this ?
    Please help me i m in critical stage of project
    Thanks in advance.
    Janak

    Can any one help ?
    Please i need help.
    Regards
    Janka

  • Problems to print xy-graph

    Hi!!
    I have problems to print a xy-graph...it gives a error:
    "append control image to report.vi is not acceptable"...Least if I try to use...
    I attached a file for my project...
    Attachments:
    ThemMonitoringSystemMOD(print).vi ‏149 KB

    I see, its still the same problem described in your other thread DAQmxbaseRead.vi error.
    The correct error message is, that a subvi is not executable..
    This is, as Wolfgang wrote, because two SubVIs accidentally have the same name. One of them is in the report palette, the other one in the daqmx palette. LabVIEW cannot handle this - only one VI will be in memory and the other one will be replaced, which leads to the error that the vi cannot be executed.
    Until this issue is going to be solved with the next daqmx driver you will have to rename the instance of the vi that is part of daqmxbase.
    Since this vi is hidden quite deeply inside the library its best to first close all labview windows, then open a new vi and place the daqmxbase read function inside. Open the VI Hierarchay (Browse meny). In the hierarchy window, go to the menu edit-> find. Search for object, as object choose VI by name. select the check data size.VI
    Once you found the vi inside the hierarchy, doubleclick it and choose save as... Save it with a different name and make sure this new name is used in the hierarchy window as well. The daqmxBase functions must be linked to the VI with the new name. Thus, closing the windows now and being asked if you want to save the changes you have to click yes.
    I hope this explanation will help you to get your code running.
    Ingo Schumacher
    Systems Engineer Sound&VibrationNational Instruments Germany

  • Graph connectivity problem-adjacency list-connected graph-Theta complexity

    I am stuck up on this problem:
    I want to find an algorithm of Theta(n+m) complexity, which will examine
    if a non-directed graph is connected (synectic).
    We assume that the representation of the graph has been made with an
    adjacency list with n vertices and m edges.
    Thanks in advance.

    A BFS or DFS from any node in your graph should be T(n+m) in case of an adjacency list (instead of a adjacency matrix). When the search is finished, compare the number of visited nodes to the total number of nodes in the graph. If they're not equal, the graph is not connected.

  • Problem of a combined graph

    Hi, guys:
    I am trying to build a combined graph with bars and line. I built two series of query.
    series 1 for bar chart:
    select null link, to_char(inv.invdate) label, sum(inv.amt) total$
    from invoices inv, payments pa, clients cl,
    (select to_date(:P390_DP_START_DATE,'MM/DD/YYYY') + rownum -1 date_in_range
    from all_objects
    where rownum <= to_date(:P390_DP_END_DATE,'MM/DD/YYYY')-to_date(:P390_DP_START_DATE,'MM/DD/YYYY')+1) days_in_period
    where inv.invoicekey=pa.invoicekey
    and cl.clientkey=inv.clientkey
    and inv.invdate=days_in_period.date_in_range
    and inv.debtorkey not in (11352, 11353)
    and exists (select tr3.transkey
    from transactions tr3
    where tr3.transkey=pa.transkey
    and tr3.type=1)
    group by inv.invdate
    order by inv.invdateseries2 with line chart
    SELECT null link, to_char(days_in_period.date_in_range) label, count(cl2.clientkey) "Total Factored Clients"
    FROM Clients cl2, 
    (select to_date(:P390_DP_START_DATE,'MM/DD/YYYY') + rownum -1 date_in_range
    from all_objects
    where rownum <= to_date(:P390_DP_END_DATE,'MM/DD/YYYY')-to_date(:P390_DP_START_DATE,'MM/DD/YYYY')+1) days_in_period
    where exists
    (select tr.transkey
    from transactions tr
    where tr.clientkey=cl2.clientkey
    and tr.type=1
    and trunc(days_in_period.date_in_range)-1-trunc(tr.postdate) <= 90
    group by days_in_period.date_in_range
    order by days_in_period.date_in_rangeHowever, the first query returns less rows than the second query, as there are some days such as weekend without total$, but with Factored Clients. In the combined graph, it shows first only rows with data for both query, and then show dates with only Factored Clients. How can I solve this problem in APEX or I have to make sure there are same number of rows in both series?
    Thanks.
    Sam

    "but am unable to do so" doesn't explain anything. What, exactly, is your problem? You can't make it compile? The graph comes out upside down?
    Before you reply, please click the link "special tokens" above the Subject of a reply. That will show you how to post code.
    Next thing is to comment closing curly braces that are more than a short distance from their opener:
      } // end of foo()
    } // end of class BarNext thing is to use methods. For example, that huge set of if tests to set "scale" should be moved into a method that sets scale:
      public void paint( Graphics g ) {
        scale = setScale( maxValue );
      } // end of paint()
      private int setScale( int max ) {
        if ( . . . // etc.
    } // end of class BarGraphAppAnother thing would be to add "else" keywords so that those "if"s wouldn't all be tested:
      if ( max > this && max < that ) scale = x;
      if ( max > this2 && max < that2 ) scale = y;
      // should be:
      if ( max > this && max < that ) scale = x;
      else if ( max > this2 && max < that2 ) scale = y;In the second way, the second test isn't evaluated if the first one is true and "scale" is set to "x".
    And while I'm looking at that particular piece of the code, how about replacing most of it with:
      private int setScale( int max ) {
        if ( max < veryLargeWhichIsSpecialCase )
          return (max + 599)/600;
        // special case goes here
      } // end of setScale()Implement some of this, and then repost the relevant section of code with a specific question, like "why does the graph come out backwards?"

  • Problem Axis Image on Graph

    Hi,
    I'm having a problem with displaying an axis on a graph. The graph is composed of layered panes and I need to display a mathematical formula on one of the axis. This was previously done using an image...
    A product evolution requires the modification of the fonts used when printing the graphs, obviously this will not be compatible with a static image. Does anyone have any ideas on how do display the text highlighted in the image shown, in a manner that allows for the changing of fonts in a dynamic manner?
    [ScreenShot001.jpg|http://www.maths.tcd.ie/~moroneyk/ScreenShot001.jpg|ScreenShot001.jpg]
    Thanks in advance,
    Kevin

    That is actually rather simple: you use animation techniques, but rather than using an animation loop to change on a set interval, you change as you are ready to show your new screen. You do this with a repaint() request.
    I usually like to implement this by doing my rendering to a BufferedImage, and then a paint override in my display object.
    public void paintComponent(Graphics g){
      g.super();
      g.drawImage(bi, 0, 0, this); //bi is a instance scoped BufferedImage that I use for rendering.
    }

  • Help.   Problem creating a visual graph.

    I am creating a push down automata. Im getting a compile error when getting 2 nodes out of a vector and placing them in the parameters of an edge which is being placed in a separate vector. Here is some code to help explain:
    public class Graph {
        Vector nodes;
        Vector edges;
        public Graph()
            nodes = new Vector();
            edges = new Vector();
            nodes.add(new Node(20, 20, '1')); //0
            nodes.add(new Node(200, 20,'2')); //1
            nodes.add(new Node(100, 100,'3')); //2
            edges.add(new Edge('a', nodes.get(0), nodes.get(1)));    //PROBLEM HERE
    public class Node {
         Vector edges = new Vector();
         int x, y;
         char nLabel;
         boolean wasVisited;
        public Node(int x, int y, char label)
           nLabel = label;
           this.x = x;
           this.y = y;
           wasVisited=false;
    public class Edge {
        char label;
        Node nodeOne;
        Node nodeTwo;
        public Edge(char lab, Node one, Node two)
            label = lab;
            nodeOne = one;
            nodeTwo = two;
        }in the graph class is where my error occurs, when im adding an edge to my edge vector.
    I'm sure it has to be something pretty simple that im missing....or maybe something im just oblivious to.
    thank you for the help.

    Ok you have two options:
    1) Use generics (recommended)
    2) Casting
    Declare the vectors as Vector<Node> and get information from [1] to learn about generics (very powerful feature and REALLY simple).
    Or when you call the Edge constructor, do this:
    edges.add(new Edge('a', (Node)nodes.get(0), (Node)nodes.get(1)));[1] http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf
    HTH : )

  • Problem copying text with graphs from web pages

    I can't copy text+graph from webpages. Copying into Pages or Microsoft Word for Mac, the text is copied the graphs are not. (With Firefox, I can't even copy text!)
    I have Parallels, and on the Microsoft side I have no problem copying both text and graphs simultaneously.
    Could you, please, advice

    Thanks.It works-sort of. I can copy into TextEdit without problems. This is probably the solution by itself because I can save it. Copying into Words (from TextEdit) didn't work. Copying into Pages partially works: the graphs are reproduced but the layout comes out funny.
    Thank you

  • Problem With Plotting a graph

    Hi,
    I need help plotting a graph.
    The situation is .... I have data of speed against time. Data is like this : a truck runs at some speed until 10 o clock. Now the driver changes time of the speed vs. time tracking device back to 9 o clock. Now if I plot this data it becomes a invalid graph as between 9 - 10 I will be having two values for the speed.
    I thought of a solution that when ever a time change occurs I will drop the speed to 0 and again start plotting the graph with next point on the scale of x axis with the new set time ...... Is this possible ? 
    Please help.
    Thanks and regards
    Anirudh

    Hi,
    Here is a photo of what I want to do with the graph.
    Here as the values that i am mappinng on x axis are repeated the graph is not one to one. Now to make it look like a one to one i want to drop it zero at the first 6. the restart the scale after 6 as 5 and continue mapping. Is this possible ?? ?? 
    Thanks and Regards,
    Anirudh.
    Attachments:
    tr1.JPG ‏113 KB

  • Problem Plotting a Line Graph

    I am trying to plot some line graphs on Numbers and am a new user.
    I can't seem to work out an issue. I want the numbers on the X axis to ascend from 0 onwards from left to right but at the moment they are descending from 10 to 0 left to right.
    How can I change this so the graph is plotted logically?
    Thanks in advance

    There are two basic types of X-Y charts.  All but one are "category" charts where the X axis is evenly spaced and the "numbers" are actually text. The data will be presented in the order listed in your table.  The other is a scatter chart. The icon for this chart looks like a shotgun blast.
    If your X axis numbers are evenly spaced (0,1,2,3...) you can use either type of chart.  Sort your table in ascending order and it will chart as you want it to.
    If your X axis numbers are not evenly spaced (such as 1,2,4,5,10) and you want the chart to be a true X-Y plot of the data, you have to use the scatter chart.  In contrast to the category charts where the X axis values must be in a header column/row, a scatter chart requires the X and Y data to be in data cells. You may have to move your data over a column so the X data is not in a header column.

  • Problem to plot the graph

    Hi, I am a beginner in Labview. In my exercise, I want to display the 1D data I got from excel in the waveform graph in Labview but it does not appear. Here is my what I have done so far. I have data in excel which has 16 rows and 2 column. I have used path function and also read spreadsheet function to display my table in labview and it works. In My labview front panel displaying now, I have 16 rows and 2 column of data. I want to analyse the 2nd column only so I use array subset function to extract the 2nd column. When I run my labview, the size of my array is now 16x1. I want to display this as a waveform graph so I choose 1D waveform graph. When I run it, the graph doesn't show anything. Please give me advice for this.
    Regards
    ade

    Hi,
    thank you very much for your reply.
    Previously, i change my excel data to CSV file before i applied it to the labview. Now,  I am planning to change my simulation from using 'read from spreadsheet" to use the activex as shown in your VI . Im still in the very basic stage of understanding what is activex, how activex and labview works together, how to display the data in the labview table (previously in the array indicator), and also how to analyse/process the data so i will need more intensive time to learn. However, in your VI, i cannot run it because there is a mismatch particularly in Variant to data Function as shown in pict below
    The thing that still make me curious until now is why i cannot plot my array of data in waveform graph. When i plot it in Chart, the plot is appear but in the  graph, there is no plot. . i try to track by mark the point that might be plotted but it shows only in point 0,0. If you dont mind, can you look at my work in my attachment?. I will attach my VI, and also the data in csv format. Thanks before
    Regards,
    Ade
    Attachments:
    Project try2.vi ‏15 KB
    LAbview Excercise.csv ‏1 KB

  • Re: is anyone else having a problem with 2-D graph of LVM data some x values showing up as negative values?

    attached is the lvm file

    This is a side post from Original Post and should be responded to there.

Maybe you are looking for