Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-24-2007, 07:19 PM
Member
 
Join Date: Dec 2007
Posts: 14
kbyrne is on a distinguished road
Accessing one class from another class through swing
I've got these 2 classes, one of them holds the gui and is called MainGui.java. and the other "Main.java" instanciates this class among other functionalities. I want to add to call a function in MainGui from the Main class and add to a Jpanel in MainGui. Any tips or advice on how best to do this?

Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-24-2007, 08:11 PM
Senior Member
 
Join Date: Jul 2007
Posts: 1,141
hardwired is on a distinguished road
Code:
class Main { // Instantiate an instance of MainGui and save a // reference to it in a member variable ("gui"). // Use this reference/variable to call methods // and access fields in the MainGui class. MainGui gui = new MainGui(); public Main() { // Use member variable to call method in MainGui. gui.addToPanel(new JPanel()); } } class MainGui extends JFrame { JPanel panel = new JPanel(new GridLayout(0,4)); public MainGui() { getContentPane().add(panel); setDefaultCloseOperation setSize setLocation setVisible } public void addToPanel(JComponent c) { panel.add(c); panel.revalidate(); } }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-29-2007, 06:34 PM
Member
 
Join Date: Dec 2007
Posts: 14
kbyrne is on a distinguished road
Thanks, that's great
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-02-2008, 09:16 AM
Member
 
Join Date: Jan 2008
Posts: 4
rajaramesh.ngate is on a distinguished road
Send a message via Skype™ to rajaramesh.ngate
Hi to java forums
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-02-2008, 02:27 PM
Member
 
Join Date: Dec 2007
Posts: 14
kbyrne is on a distinguished road
Hi there, happy new year
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-03-2008, 08:54 AM
Member
 
Join Date: Jan 2008
Posts: 4
rajaramesh.ngate is on a distinguished road
Send a message via Skype™ to rajaramesh.ngate
Hiii
Hi we can access once class from another class using java swings bcoz java swing is completely written in pure java .so we can do it .
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


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

vB 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
Java Swing class capturing output to the console Java Tip Java Tips 0 03-12-2008 12:24 PM
Accessing inner class from outer class (an example) Java Tip Java Tips 0 02-17-2008 10:03 AM
An example of accessing outer class from inner class Java Tip Java Tips 0 02-17-2008 10:01 AM
Inner class accessing outer class Java Tip Java Tips 0 02-17-2008 09:59 AM
Accessing list out another class Preethi New To Java 18 01-08-2008 08:04 AM


All times are GMT +3. The time now is 08:28 AM.


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