Results 1 to 3 of 3
  1. #1
    benhelmer is offline Member
    Join Date
    Aug 2011
    Rep Power

    Default Help! My coode is doing something wacky I do not know whats wrong here!

    Sorry, but i don't know how to put my message into a seperate box.
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class A extends JFrame{
    	public JButton single;
    	public JTextField doubl;
    	public static void main(String[] args){
    		DisplayMode DM = new DisplayMode(1600,1200,16, DisplayMode.REFRESH_RATE_UNKNOWN);
    		A a = new A();;
    	[B]handler handle = new handler();[/B] 
    	[B]single[U].[/U]addActionListener([U]handle[/U]);[/B]   [I]this is the problem section[/I]
    	private class handler implements ActionListener {
    		public void actionPerformed(ActionEvent event) {
    		String string = " ";
    			if(event.getSource()== single)
    				string = String.format("the game has not been made yet");
    	public void run (DisplayMode DM){
    		setFont(new Font("ARIAL", Font.BOLD, 40));
    		AA A = new AA();
    			A.fullscreen(DM, this);
    			}catch(Exception ex){}
    	public void paint(Graphics g){
    		if(g instanceof Graphics2D){
    			Graphics2D G = (Graphics2D)g;
    			G.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    		single = new JButton("start");
    		g.drawString("Click the screen to start.", 800, 600);

    Please tell me what is wrong. Thank you
    Last edited by Norm; 08-21-2011 at 07:23 PM. Reason: Added code tags

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    how to put my message into a seperate box.
    Do you mean like a dialog box that popups over the frame?
    See the JOptionPane class for methods to create and display messages.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power


    What's the point behind using String#format with an argument that doesn't format anything?

    There's no need to test instanceof Graphics2D. Since around Java 1.1 (maybe 1.2) all Graphics objects are instances of Graphics2D.

    Don't create and add components in a painting method override, ever. You have no control over when and how often the method is invoked.

    Swing components need to be constructed and their methods called only on the EDT. Not in the main Thread. And sleep(...) must never be called on the EDT. Use a Swing Timer for scheduling a delay.

    Custom painting is done by overriding paintComponent(...) in a JPanel or other JComponent, not by overriding paint(...) in a top level window like JFrame.

    Better go through the tutorial: Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)


Similar Threads

  1. whats wrong with my code
    By naved in forum New To Java
    Replies: 5
    Last Post: 07-15-2011, 02:06 AM
  2. whats wrong
    By atenv in forum New To Java
    Replies: 6
    Last Post: 06-15-2010, 01:55 PM
  3. whats is wrong with this app??
    By mrajan in forum New To Java
    Replies: 4
    Last Post: 06-09-2010, 10:56 PM
  4. Database help... whats wrong?
    By neosnokia in forum JDBC
    Replies: 4
    Last Post: 06-09-2009, 11:17 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