Results 1 to 2 of 2
  1. #1
    Mikki is offline Member
    Join Date
    Jun 2012
    Rep Power

    Default The text and the buttons are overlapping

    Hi ,
    Can someone help me here. Please find my code below for your reference. When I run this program, the Buttons are on top of the "Welcome New Hire"text. What am I doing wrong. I am not using Swings but awt.

    Java Code:
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.Container;;
    public class NewHireApplet extends Applet implements ActionListener
    	public Button setup = new Button("SETUP");
    	public Button training = new Button("TRAINING");
    	private String s = "Welcome New Hire";
    	public void init()
    		setSize(300, 300);
    	}//end of init()
    	public void paint(Graphics g)
    		Font myFont1 = new Font("Serif",Font.BOLD,24);
    		Font myFont2 = new Font("Serif",Font.BOLD,12);
    		Dimension d = getSize();
    		//determine x and y co-ordinates
    		FontMetrics fm = g.getFontMetrics();
    		int x = d.width/2 - fm.stringWidth(s)/2;
    		int y = d.height/2 - fm.getHeight();
    		g.drawString(s , x, 20);
    		g.drawString("Welcome new hire to UB. This applet will help you get started.Have fun", x, 280);
    	}//end of paint()
    	public void actionPerformed(ActionEvent arg0) {
    		// TODO Auto-generated method stub
    Last edited by Mikki; 10-04-2012 at 07:17 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Washington, DC
    Rep Power

    Default Re: The text and the buttons are overlapping

    I'm not sure what you expect to happen differently. If the text was drawn on top of the button, so would the background of the Applet, and the button would not be visible.
    How to Ask Questions the Smart Way
    Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
    Static Void Games forum - Come say hello!

Similar Threads

  1. Replies: 2
    Last Post: 08-11-2011, 05:02 PM
  2. Replies: 0
    Last Post: 11-30-2010, 05:04 PM
  3. AWT: Painting buttons and text areas in a canvas
    By chappa in forum AWT / Swing
    Replies: 6
    Last Post: 01-09-2010, 02:37 PM
  4. Help with overlapping JPanels
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 03-09-2009, 10:19 PM
  5. Searching a string from a text file using Swing Buttons
    By in forum AWT / Swing
    Replies: 2
    Last Post: 09-15-2008, 09:50 AM

Posting Permissions

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