score:1
the problem is that you have duplicate variables home
and clients
.
the folllowing is your modified code to fix that, with comments on the changed lines (five lines total) :
import java.awt.cardlayout;
import java.awt.eventqueue;
import java.awt.event.actionevent;
import java.awt.event.actionlistener;
import javax.swing.jbutton;
import javax.swing.jframe;
import javax.swing.jpanel;
import javax.swing.border.emptyborder;
public class ia extends jframe {
private final jpanel contentpane;
// private final jpanel home; // removed
// private jpanel clients; // removed
/**
* launch the application.
*/
public static void main(final string[] args) {
eventqueue.invokelater(new runnable() {
public void run() {
try {
ia frame = new ia();
frame.setvisible(true);
} catch (exception e) {
e.printstacktrace();
}
}
});
}
/**
* create the frame.
*/
public ia() {
setdefaultcloseoperation(jframe.exit_on_close);
setbounds(100, 100, 450, 300);
contentpane = new jpanel();
contentpane.setborder(new emptyborder(5, 5, 5, 5));
setcontentpane(contentpane);
contentpane.setlayout(new cardlayout(0, 0));
final jpanel home = new jpanel();
contentpane.add(home, "name_714429679706141");
home.setlayout(null);
final jpanel clients = new jpanel(); // moved up
contentpane.add(clients, "name_714431450350356"); // moved up
clients.setlayout(null); // moved up
jbutton btnclients = new jbutton("clients");
btnclients.addactionlistener(new actionlistener() {
public void actionperformed(final actionevent e) {
home.setvisible(false);
clients.setvisible(true);
}
});
btnclients.setbounds(160, 108, 89, 23);
home.add(btnclients);
jbutton btnhome = new jbutton("home");
btnhome.addactionlistener(new actionlistener() {
public void actionperformed(final actionevent e) {
clients.setvisible(false);
home.setvisible(true);
}
});
btnhome.setbounds(169, 107, 89, 23);
clients.add(btnhome);
}
}
score:0
i would take a look at this post, however i have a feeling you'll need to use a actionlistener to get this done... java swing. opening a new jpanel from a jbutton and making the buttons pretty i would of left this as a comment but apparently you need 50 rep for that...
this link might be more helpful.. how to open a new window by clicking a button
score:0
when the following code is invoked the clients
variable equals to null.
jbutton btnclients = new jbutton("clients");
btnclients.addactionlistener(new actionlistener() {
public void actionperformed(actionevent e) {
home.setvisible(false);
clients.setvisible(true);
}
});
write this:
jpanel clients = new jpanel();
contentpane.add(clients, "name_714431450350356");
clients.setlayout(null);
jbutton btnhome = new jbutton("home");
btnhome.setbounds(169, 107, 89, 23);
clients.add(btnhome);
before you add the action listener
Source: stackoverflow.com
Related Query
- How to open a new JPanel with a JButton?
- Having a JButton open a new JPanel
- How to download/clone a new branch from my server git repository into an already created local git repository in my PC with Eclipse EGit
- How to open run configurations window in Eclipse with shortcut?
- How to open existing C++ project with Eclipse?
- How to use an existing Project as a template for a new one with Eclipse (CDT)?
- How to surround some html code in Eclipse with new tag (shortcut)?
- How do I use Django Command Extensions with a new Eclipse/Pydev run configuration
- How to create new folder in Eclipse Helios CDT with symbolic link?
- How do you make new editors open in another screen?
- how to open project with Java EE Eclipse?
- In Eclipse, how do I make a .pdf file open with the System Editor by default?
- How to open a xml file with my editor in eclipse plugin development?
- Eclipse-RCP: How to add a plug-in with an application model into a perspective of a new RCP application?
- How to build an Eclipse plugin with Maven/Tycho for use in the "Install New Software" dialog
- How do I create a new eclipse project for jetty from a tomcat based project and versioned with svn/subclipse?
- How can I create a new Role with openstack4j?
- How to open *.class files with decompiler by default in Eclipse?
- Eclipse plug-in: How to create a new menu for eclipse plugin with key combination?
- How do I set up a new Java project with Eclipse, Maven, Grails and git?
- How to open a PHP file with a JS or HTML Editor in Eclipse
- How to start a new backend web project in Eclipse with Gradle?
- how to merge a new workspace with existing remote repository in bit bucket
- eclipse - how to open a text-like file type if it's registered with another application
- How do I open a new workbench window (with its own WorkbenchWindowAdvisor) from an existing workbench window?
- How do I open a new tab in chrome using the Actions class
- Eclipse: how to open a search-found file in a new editor tab?
- Eclipse: How do I quickly open a folder (in the package, project or resource explorer) with a keyboard shortcut?
- How to import an Android project in to eclipse with out creating a new one from source?
- How can I open a new browser tab in Eclipse PDT?
More Query from same tag
- Request android.permission.CHANGE_WIFI_STATE
- Eclipse ADT giving wrong smallest width selector
- Android 2.2 SDK - System.out.println JSON string to long for LogCat?
- how do i fix the error "conversion to dalvik format failed with error 1"?
- Eclipse pausing without a breakpoint
- Cloud Foundry plug-in is not installable into pulse managed eclipse (due to missing joda time osgi bundle)
- How to import SQLite database in Eclipse IDE
- Is it possible to change the icon of a desktop application in javafx?
- lazylist adapter issue while scrolling
- External jar configuration when debugging JSP in eclipse
- Change Return type error in Eclipse
- How to increase the heap size of WebSphere Application Server V8.5 Liberty Profile in Eclipse?
- JavaRebel with a Multi-module Enterprise Project in Maven
- ECLIPSE - Object Repository Program - NullPointerException Error Shown
- Jquery is not working in Eclipse Neon
- The Compiler Warning shows up even when the import it shows as unused, is actually not being used in the class
- Creating Desktop Application using Netbeans or Eclispse on Mac
- Copied Project Steps Through Original Project When Debugging in Ecplise
- Setting start levels & auto-start of Eclipse plug-ins: p2.inf vs product definition
- Previously working Java servlet now no longer working after 'Clean' - Tomcat v7.0 and Eclipse
- Get a file location in Eclipse Plugin
- Java- Eclipse error
- Building multiple apks from on android app source
- Class "model.Address" is listed in the persistence.xml file but not mapped
- Trying to make a fencing map using terrain representation
- Is there something wrong with my Eclipse ADT?
- What does the support of JRebel for an app (non-IDE) mean?
- PyDev in Eclipse seems not supporting incremental find
- Open in default browser exception
- How is launching a program in eclipse different from launching it in a terminal?