Create my Java wizard window

xiaoxiao2021-03-06  39

First, declare, even the rookie! So the master should be intimate before watching this article. Please don't break the mouth after reading it. Thank you! Welcome friendly comments! Recently, it is greatly interested in making a form (, another business man). I don't think about this form all day. How is the form designed? If you can't wait for a program that mobilize the program in the computer, you will be carefully studied (the fire into the magic, -_- |||) . Today, I pondered the way of making a guide, get out of everyone to discuss discussions ... [Sorry, I repeated the Java tutorial today, I found that the Cardlayout layout is very unused, so I forgot -_ | . I have modified, apologize again! --Nicholas Lin @ Jan 21, 2005] During a wizard, there may be many JPANELs, if the temporary load is used, it will be slower when running. So I use it all when the wizard is started, so it will be slower when starting, but it is fast. Observing findings, and in contrast to the layers made of PS, Java is loaded with the components, and the components loaded will override the components behind. This way we can load all JPanel in the same location. When you want to display the next jPanel, just put the current setvisible (false); then repainT (); The problem is now, some components will be displayed through the previous JPanel, such as JtextField. How to do it? The JPanel all setvisible (false) that does not need to be displayed; the whole world is quiet ... Now we solve a problem with a display. Next problem is next. The wizard is not available for use. First we have to capture the user's input, then determine if the user's input is legal, invalid input To generate an error prompt, valid input can continue. Of course, we can't do these things in the GuideFrame class, otherwise it will not be reused. So we have to declare an interface:

Package nicholas.swing; public interface checkable {public boolean check (); public string getErrorMessage ();} A Abstract Class:

package nicholas.swing; import javax.swing *;. public abstract class CheckPanel extends JPanel implements Checkable {public CheckPanel () {} public abstract String getTitle (); public abstract String getDetail ();} Now we can use subclass CheckPanel To implement all input check operations, and GuideFrame can just get the results of the check and decide whether to call the next CheckPanel. Here is the code of GuideFrame:

package nicholas.swing; import javax.swing *;. import java.awt *;. import java.awt.event *;. public class GuideFrame extends JFrame implements ActionListener {private CheckPanel panel []; private JPanel deck; private JButton nextButton; private JButton prevButton; private JButton exitButton; private CardLayout cardManager; private JLabel titleLabel; private JLabel detailLabel; private JLabel imageLabel; private int current; public GuideFrame () {super (); current = 0;. getContentPane () setLayout (null); setupUI (); setDefaultCloseOperation (JFrame.DO_NOTHING_ON_CLOSE); setResizable (false); setSize (500,360); Dimension screen = getToolkit () getScreenSize ();.. setLocation ((screen.width-getSize () width) / 2, (screen . HEIGHT - GETSIZE (). HEIGHT) / 2); show (); pick void setpanel (CheckPanel P []) {panel = p; cardmanager = new cardlayout (); deck = new jPanel (cardmanager); for (int i = 0; I

prevButton = new JButton ( "Back"); prevButton.setBounds (245,298,75,21); prevButton.addActionListener (this); prevButton.setVisible (false); nextButton = new JButton ( "next"); nextButton.setBounds (325,298,75,21); nextButton.addActionListener (this); exitButton = new JButton ( "cancel"); exitButton.setBounds (413,298,65,21); exitButton.addActionListener (this);. getContentPane () add (prevButton GetContentPane (). Add (nextbutton); getContentPane (). Add (exitbutton);} private void quit () {} public void actionPerformed (AE.Getsource () == exitbutton {int result = JOPTIONPANE.SHOWCONFIRMDIALOG (this, "You confirm that you want to exit the presentation guide? / N All information will be lost." EXIT (0);}} else if (ae.getsource () == nextButton) {IF (Panel [current] .Check ()) {// can do next job current ; if (current == 1) {Prevbutton. SetVisible (TRUE);} f (current == (panel.length-1) {prevbutton.setvis ible (false); NextButton.Settext ("Complete");} else = = = =el.length) {quit (); return;} CardManager.next (deck);} else {// cannot Continue Joptionpane.showMessageDialog JOPANE.SHOWMESSAGEDIALOG (this, panel [current] .GeterrorMessage (), "Warning", JOPANE.Error_Message); return;}} else {current -; cardmanager.previous (deck); if (current == 0) {Prevbutton.SetVisible False);}}}} where Titlelabel, detaillabel, imagelabel can be placed in CheckPanel, but personal feeling is better in guideframe, just checkpanel jumps, you should give the first two Jlabel assignments. (the code is not given, Even lazy ...).

转载请注明原文地址:https://www.9cbs.com/read-71705.html

New Post(0)