Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-02-2008, 02:23 AM
Member
 
Join Date: Dec 2008
Posts: 1
Rep Power: 0
tomjrmkay is on a distinguished road
Default Problem with Applet
hi i have written a java applet just for messing around with because its my first one and i have a question. this is my code:
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Keyboard1 extends Applet
   implements KeyListener, MouseListener {

   int width, height;
   int x, y, ex, ey;
   String s = "";
   String enter = "Mouse is NOT in the applet.";
// Color changing buttons

   CheckboxGroup radioGroup;
   Checkbox radio1;
   Checkbox radio2;
   Checkbox radio3;

// End Color changing buttons

   public void init() {
      width = getSize().width;
      height = getSize().height;
      setBackground( Color.gray );

      x = width/2;
      y = height/2;

      addKeyListener( this );
      addMouseListener( this );

// Color changing buttons

setLayout(new FlowLayout());
radioGroup = new CheckboxGroup();
radio1 = new Checkbox("Red",radioGroup,false);
radio2 = new Checkbox("Green",radioGroup,true);
radio3 = new Checkbox("Blue",radioGroup,false);
add(radio1);
add(radio2);
add(radio3);

//End Color chaning buttons
   }

   public void keyPressed( KeyEvent e ) { }
   public void keyReleased( KeyEvent e ) { }
   public void keyTyped( KeyEvent e ) {
      char c = e.getKeyChar();
      if ( c != KeyEvent.CHAR_UNDEFINED ) {
         s = s + c;
         repaint();
         e.consume();
      }
   }

   public void mouseEntered( MouseEvent e ) {
      enter = "Mouse IS in the applet.";
      repaint();
      e.consume();
   }
   public void mouseExited( MouseEvent e ) {
      enter = "Mouse is NOT in the applet.";
      repaint();
      e.consume();
   }
   public void mouseMoved( MouseEvent e ) {  // called during motion when no buttons are down
      ex = e.getX();
      ey = e.getY();
      repaint();
      e.consume();
   }
   public void mouseDragged( MouseEvent e ) {  // called during motion with buttons down
   }
   public void mousePressed( MouseEvent e ) { }
   public void mouseReleased( MouseEvent e ) { }
   public void mouseClicked( MouseEvent e ) {
      x = e.getX();
      y = e.getY();
      s = "";
      repaint();
      e.consume();
   }

   public void paint( Graphics g ) {
      g.setColor( Color.magenta );
      g.drawLine( x, y, x, y-10 );
      g.drawLine( x, y, x+10, y );
if (radio1.getState()) {
g.setColor( Color.red );
} else if (radio2.getState()) {
g.setColor( Color.green ); 
} else {
g.setColor( Color.blue );
}
      g.drawString( s, x+10, y-3 );
      g.setColor( Color.cyan );
      g.drawString( enter, 10, 25 );
      g.setColor( Color.red );
      g.drawString( "Click where you want to type then type something.", 10, 10 );
      g.setColor( Color.yellow );
      g.drawString( "Your Coords: ("+x+", "+y+")", 10, 40 );
   }
}
When i try to change the color it doesnt work. nothing shows up. it worked fine before i added the changing colors so if anyone knows please reply. thanks.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-19-2008, 10:35 AM
Senior Member
 
Join Date: Dec 2008
Location: Hong Kong
Posts: 393
Rep Power: 1
mtyoung is on a distinguished road
Default
hi,

i think checkbox objects should add Mouse Listener
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
applet problem shwein New To Java 2 10-27-2008 11:17 PM
Serious applet problem willemjav Java Applets 1 03-25-2008 05:01 PM
applet problem plz HELP shibajisanyal Java Applets 1 01-09-2008 01:47 AM
problem with jscrollbar in my applet leonard Java Applets 1 08-03-2007 11:39 PM
Applet problem Ed Java Applets 2 07-02-2007 03:35 PM


All times are GMT +2. The time now is 12:20 AM.



VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org