Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add panel in from other class  RSS feed

 
Ranch Hand
Posts: 268
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.
I have two classes. I need to display the JPanel from second class. The code is below

Login.java



Main.java



I get the error at line 59 i.e mpanel = new JPanel(si);

I need a little help please point at the mistake.

Thanks and Regards
alexander
 
Sheriff
Posts: 21255
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JPanel does not have a constructor that takes an ActionListener as an argument.

Can you tell us, in words, what you are trying to do on that line?
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your Main application isn't a JPanel and doesn't offer a JPanel that can be used anywhere. Instead it is geared to create a JFrame and displays an app in the JFrame. Fortunately it can be modified to allow us to extract its JPanel. Have a look at some changes I've made:



and then in Login:
 
Time flies like an arrow. Fruit flies like a banana. Steve flies like a tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!