Answer the question
In order to leave comments, you need to log in
How to access a JPanel component in Java?
There is a MyFrame class, which describes the creation of a frame, and in this class the JPanel component is created.
And there is an Example class that creates a Button, and then I want to add that Button to the JPanel. But an error pops up: panel cannot be resolved. Where is the mistake?
class MyFrame extends JFrame
{
public MyFrame()
{
setSize(300, 400);
setTitle("Example");
JPanel panel = new JPanel();
panel.setBackground(Color.green);
add(panel);
}
}
class Example
{
public Example()
{
JButton Button = new JButton("oooooo");
panel.add(Button); //в этой строке показывает ошибку
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question