how to create multiple frames in java swing component
i am new to java s开发者_运维技巧wing component. please tell me how to create multiple frames. My requirement is ,base frame should contain 2 radio buttons and if i click anyone radio button it should go to other frame and it should display 4 check boxes.
Please advice
Why don't you read the docs and tutorial? http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/frame.html
check out how CardLayout works
https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html
if you only want to switch between the windows:
- Add jPanel to your jFrame which will contain all jPanels you want to switch between (let's call it jPanelMain)
- Set CardLayout in jPanelMain
- Create jPanels you want to switch between with the stuff you need there
Add Action Listener to the radio button, example
private void jButtonActionPerformed(java.awt.event.ActionEvent e) { jPanelMain.removeAll(); jPanelMain.repaint(); jPanelMain.revalidate(); jPanelMain.add(jPanel1); jPanelMain.repaint(); jPanelMain.revalidate(); }
精彩评论