Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

drawing string to JPanel

843804Mar 2 2005 — edited Mar 2 2005
I have a program which takes code from a database and draws them to the JPanel. But it is going really slow and not working other times at all. I don't know what the problem is. It draws to the canvas with an action listener on a button., I'll show the code involved. If anyone has any ideas I would really appreciate it.
draw.compile.addActionListener(new ActionListener()
        {
        	public void actionPerformed(ActionEvent e23)
        	{
        		loadText();



        	}
        });

public void loadText()
  {
     try
     {

  	Statement statement = connection.createStatement();
  	ResultSet rs = statement.executeQuery("SELECT * FROM submit WHERE file_name = '" + fileName + "'");

  	rs.next();

  	String user1 = rs.getString("student_id");
  	//System.out.println("one1 :" + one1);

  	String filename1 = rs.getString("file_name");
  	//System.out.println("two1 : " + two1);

        InputStream textStream = rs.getAsciiStream("file");
        BufferedReader textReader = new BufferedReader(
                new InputStreamReader(textStream));

        codeLine = textReader.readLine();

        x = 0;
        y = 0;

        while(codeLine != null)
        {
           y = y + 12;
           //fileText.append( line + "\n");
           //canvasPad.drawTheString(line, x, y);       giveFeed.canvasPad.mode_paint
           draw.drawPanel.drawText(Color.black, x, y, codeLine, 0);

           codeLine = textReader.readLine();
        }
        textReader.close();

        Timestamp ts1 = rs.getTimestamp("ts");
        //System.out.println(three1);

        //textReader.close();

        rs.close();
     }catch (SQLException e)
     {
        System.err.println(e);
     }
     catch(IOException ioX)
     {
        System.err.println(ioX);
     }
  }


and the drawText
synchronized public void drawText(Color color, int x, int y,
	       String text, int mode)
    {
	Graphics g = offScreen.getGraphics();
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);


	if (mode == this.mode_xor)
	    {
		g2.setXORMode(Color.white);
	    }
	else
	    {
		g2.setColor(color);
	    }

	g2.setFont(new Font("Times Roman", Font.PLAIN, 10));

	g2.drawString(text, x, y);


	g.dispose();
    }
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 30 2005
Added on Mar 2 2005
2 comments
150 views