开发者

Java can't find symbol [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*; 

public class Stuff extends Applet implements ActionListener
{
    Button okButton; 
    public void init() 
   {    
       setLayout(new FlowLayout());
       okButton = new Button(""); 
       add(okButton); 

       okButton.addActionListener(this); 
   }
   public void paint(Graphics g)
   { 
       if (okButton.getState()) 
       g.setColor(Color.black); 
       g.drawRect(20, 20, 200, 200);
   }
   public void actionPerformed(ActionEvent evt) 
   { 
        if (evt.getSource() == okButton)  
            repaint()开发者_如何学Go;
   }
}


I think button don't has a state. It isn't like a Checkbox to get the state as if it is marked or not. So, okButton.getState() is the error.

An explanation of what you are trying to achieve would help every one to help you. Don't just post the code, leaving to us to decipher what you are trying to achieve .


java.awt.Button has no method getState. Did you mean to add an ActionListener to it so you can know when it has been clicked?


i just run your program i see the button just add cast of okButton....

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜