DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2009
    Posts
    5

    The drawString method.

    Ok, im a begginer and im having trouble using the drawstring method... i get no error when compiling and no error in the console when running the only problem is that my string doesnt show.... i simply get my blank frame with no string showing... heres my code:

    Code:
    public class Main 
    	extends Class1 {
    	
    	public static void main (String args[])
    	{
    	new Main();
    	}
    	
    	public static void println(String s)
    	{
    		System.out.println(s);
    	}
    	
    	public void method1(int x, int y, boolean bool, boolean b, String s)
    	{
    		frame.setSize(x,y);
    		frame.setVisible(bool);
    		frame.setResizable(b);
    		frame.setTitle(s);
    		println("Frame Loaded Sucessfully");
    	}
    	
    	public Main() {
    	method1(800,500,true,false,"In search of a name");
    	method2(50,50,"enfin");
    	}
    	
    }
    and in my other class :

    Code:
    import java.awt.Frame;
    import java.awt.*;
    import java.applet.Applet;
    import javax.swing.JTextField;
    
    public abstract class Class1 {
    
    Frame frame = new Frame();
    
    	public void method2(int x, int y, String s)
    	{
    		frame.getGraphics().drawString(s,x,y);
    		frame.repaint();
    	}
    
    }
    If you got any idea why my string aint showing please tell me... is there a method like .setVisible(true); that i have to add or something?

    Thanks you

  2. #2
    Join Date
    Sep 2009
    Posts
    5
    fixed myself, thanks anyway

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    What did you do?

    Your solution may help someone else with the same or similiar problem.

    Thanks.
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  4. #4
    Join Date
    Sep 2009
    Posts
    5
    i changed my method2 to this :

    Code:
    	public void method2(int x, int y, String s)
    	{
    		try{
    			Graphics g = frame.getGraphics();
    			Graphics2D g2 = (Graphics2D)g;			
    			g2.drawString(s,x,y);
    			println("String "+s+" loaded Sucessfully");
    		}catch (Exception e){
    		println("Error while loading String "+s+"");
    		}
    	}

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Thank you
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

Similar Threads

  1. hashCode method execution
    By Atanu_Banerjee in forum Java
    Replies: 11
    Last Post: 08-24-2008, 05:37 PM
  2. Serious problem with a website!
    By Loham in forum Java
    Replies: 1
    Last Post: 06-13-2008, 08:11 AM
  3. Replies: 1
    Last Post: 04-13-2006, 04:57 AM
  4. depricated method needs changing
    By Alan Shiers in forum Java
    Replies: 0
    Last Post: 03-15-2002, 12:51 PM
  5. Replies: 3
    Last Post: 04-13-2001, 09:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links