Results 1 to 2 of 2
- 10-04-2012, 05:47 PM #1
Member
- Join Date
- Jun 2012
- Posts
- 16
- Rep Power
- 0
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() { setBackground(Color.blue.darker()); setSize(300, 300); add(setup); setup.addActionListener(this); add(training); training.addActionListener(this); }//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.setColor(Color.WHITE); g.setFont(myFont1); g.drawString(s , x, 20); g.setFont(myFont2); g.drawString("Welcome new hire to UB. This applet will help you get started.Have fun", x, 280); }//end of paint() @Override public void actionPerformed(ActionEvent arg0) { // TODO Auto-generated method stub } }Last edited by Mikki; 10-04-2012 at 07:17 PM.
- 10-04-2012, 06:11 PM #2
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 - Play indie games, learn from game tutorials and source code, upload your own games!
Similar Threads
-
middle buttons and bottom text area boxes missing in GUI
By dekon in forum New To JavaReplies: 2Last Post: 08-11-2011, 05:02 PM -
Change text on the separator between Installer panels and Navigation buttons
By salman.kagzi in forum New To JavaReplies: 0Last Post: 11-30-2010, 05:04 PM -
AWT: Painting buttons and text areas in a canvas
By chappa in forum AWT / SwingReplies: 6Last Post: 01-09-2010, 02:37 PM -
Help with overlapping JPanels
By xcallmejudasx in forum New To JavaReplies: 2Last Post: 03-09-2009, 10:19 PM -
Searching a string from a text file using Swing Buttons
By pradeep1_mca@yahoo.com in forum AWT / SwingReplies: 2Last Post: 09-15-2008, 09:50 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks