Results 1 to 6 of 6

Thread: Paint method

  1. #1
    subbus is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Paint method

    how to fetch a value from a text box from FormUi class and send to the paint(Graphics g) method in Paint.class?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Paint method

    Quote Originally Posted by subbus View Post
    how to fetch a value from a text box from FormUi class
    What is a "text box"?
    What is the "FormUi class"?

    .. and send to the paint(Graphics g) method in Paint.class?
    What is the Paint class?

    Perhaps you want to tell us the details of your problem?

  3. #3
    subbus is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: Paint method

    I have two class files formUI and paint. formUI has text box component from which i need to fetch the string value and pass it on to the paint(Graphics g) method.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Paint method

    Quote Originally Posted by subbus View Post
    I have two class files formUI and paint. formUI has text box component from which i need to fetch the string value and pass it on to the paint(Graphics g) method.
    OK, but I'm assuming that you've got a Swing application, and I thought I knew all of the standard Swing components in existence in particular the text components, but I've never heard of a "text box". Can you clarify this some more.

    As for the gist of your question, the devil's in the details: how you extract information will depend much on the program code and overall structure, things we still know nothing about. Again, you may wish to tell us much more of the details about your problem and your code. You're almost asking it as if we have magic that allows us to see the code you've not shown and be able to understand problems that you've not stated. I wish we had these abilities, but unfortunately, we don't.

  5. #5
    subbus is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: Paint method

    Java Code:
    public class Ex1 extends JDialog{
    	
    	JDialog dlg=new JDialog();
    	JTextField txt=new JTextField(10);
    	JButton click=new JButton("Print");
    	String mesg;
    	PaintScreen p=new PaintScreen();
    	public void drawEx1() {
    		dlg.setLayout(new FlowLayout());
    		dlg.add(txt, FlowLayout.LEFT);
    		dlg.add(click, FlowLayout.LEFT);
    		click.addMouseListener(new MouseAdapter() {
    			public void mouseClicked(MouseEvent me)
    			{
    				call();
    			}
    		});
    		dlg.setSize(100, 100);
    		dlg.setVisible(true);
    	}
    	public void call()
    	{
    		mesg=txt.getText();
    		p.display(mesg);
    		
    		
    	}
    	
    	public static void main(String[] a)
    	{
    		Ex1 obj=new Ex1();
    		obj.drawEx1();
    		
    	}
    
    }
    Java Code:
    public class PaintScreen extends JDialog {
    	
    	String name="";
    	JDialog dlg;
    	   void display(String mesg)
    	   {
    		   name=mesg;
    		   System.out.println("passed value:"+name);
    		   dlg=new PaintScreen();
    		   dlg.setSize(200, 200);
    		   dlg.setVisible(true);
    		   
    	   }
    	 public void paint(Graphics g)
    	 {
    		 
    		 
    		 g.drawString(name, 100, 50);
    // here i am getting a null pointer exception
    	 }
    }
    Last edited by subbus; 06-20-2012 at 01:35 AM.

  6. #6
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,400
    Rep Power
    25

    Default Re: Paint method

    To see some of what your code is doing(start of debugging), change the value of the name variable:
    String name="Initial value";
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Paint method, need help
    By PeterPan in forum AWT / Swing
    Replies: 2
    Last Post: 01-15-2012, 12:35 AM
  2. paint method
    By larry_d1990 in forum Advanced Java
    Replies: 1
    Last Post: 01-09-2011, 05:45 PM
  3. Using Graphics outside of a paint method
    By Catfish1 in forum New To Java
    Replies: 6
    Last Post: 10-26-2010, 08:57 PM
  4. how to add more than one paint method
    By gautham in forum Java 2D
    Replies: 2
    Last Post: 04-06-2010, 07:07 AM
  5. an error in paint method
    By hopey in forum Java 2D
    Replies: 7
    Last Post: 04-24-2009, 10:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •