Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Java Error

Name: Anonymous 2009-03-19 19:19

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TwoButtons extends JFrame implements ActionListener
{
  JButton redButton ;
  JButton grnButton ;

  // constructor for TwoButtons
  public TwoButtons(String title)                          
  {
    super( title );
   
    redButton = new JButton("Red");
    grnButton = new JButton("Green");
    redButton.setActionCommand( "red" );   // set the  command
    grnButton.setActionCommand( "green" ); // set the  command  

    // register the buttonDemo frame
    // as the listener for both Buttons.
    redButton.addActionListener( this );
    grnButton.addActionListener( this );    

    setLayout( new FlowLayout() );
    add( redButton );                     
    add( grnButton );
   
    setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );  
  }

  public void actionPerformed( ActionEvent evt)
  {
    // check which command has been sent
    if ( evt.getActionCommand().equals( "red" ) )
      getContentPane().setBackground(  Color.red  );   
    else
      getContentPane().setBackground( Color.green );   

    repaint();
  }

  public static void main ( String[] args )
  {
    TwoButtons demo  = new TwoButtons( "Click a Button" ) ;
   
    demo.setSize( 200, 150 );    
    demo.setVisible( true );     
  }
}


This is fucking gay. I'm trying to learn java from a fucking tutorial, and the only GUI example it gave me to practice off is giving me a fucking error. Can someone point it out?

Name: Anonymous 2009-03-19 19:21

Try a Python compiler

Name: Anonymous 2009-03-19 19:22

>>2
u think you're cool?

Name: Anonymous 2009-03-19 19:23

>>3
YES

Name: Anonymous 2009-03-19 19:23

>>3
Hahaha, you think you're tough huh?

Name: TTHBCARWTFT MEME FAN 2009-03-19 19:54

This thread has been closed and replaced with the following thread:

Subject:
Compiling Java code in a Python compiler
Name: Anonymous
Email:

It still doesn't work.

Name: Anonymous 2009-03-19 20:04

>>1
I just copied and pasted this, compiled and ran and it worked perfectly. The only thing I can think that would be wrong is perhaps the file it is in is not named after the class. To clarify, the file that contains a class must have exactly the same (case sensitive) name as the (public) class in the file.
Here the file should be called "TwoButtons.java" and should be run with:
>javac TwoButtons.java //compiling
>java TwoButtons //running

Name: Anonymous 2009-03-19 20:07

>>7
Don't encourage this shit. He's just a /pr/ faggot trolling.

Name: Anonymous 2009-03-19 20:21

>>6
try the -funroll-all-java option.

Name: Anonymous 2011-02-03 1:18

Name: Anonymous 2011-02-04 13:29

Don't change these.
Name: Email:
Entire Thread Thread List