Cet article partage le code spécifique affiché sur l'interface d'enregistrement de connexion de swing pour votre référence. Le contenu spécifique est le suivant
Environnement de développement: Eclipse Neon.3 Release (4.6.3)
J'utilise la version Javaee. Afin de faciliter la conception de l'interface, je dois installer le plug-in WindowBuilder, qui peut être recherché directement sur le marché.
Description: reportez-vous à la vidéo de Kaige pour apprendre de manière synchrone
Effet d'interface
Interface de connexion
Interface d'enregistrement
Technologies clés
Ce projet utilise le plug-in d'apparence Java Swing et utilise des images (cliquez sur SRC Cliquez avec le bouton droit sur le dossier pour nommer Res et copier l'image Login.jpg)
Code source
com.lsh.view.logindialog
package com.lsh.view; import java.awt.borderlayout; import javax.swing.jbutton; importer javax.swing.jdialog; import javax.swing.jpanel; import javax.swing.border.emptyborder; import javax.swing.jtextfield; import javax.swing.jLabel; import java.awt. java.awt.event.actionEvent; import javax.swing.imageicon; import javax.swing.border.titledborder; import com.lsh.util.imagescale; @suppresswarnings ("serial") public Logindialog étend jdialog {private final jpanelpanel = new Jpanel ();); Jtexfield privé Textfield; privé jTextField TextField_1; privé jTextfield TextField_2; privé jTextfield TextField_3; privé jTextfield TextField_4; privé jTextfield TextField_5; private static final int dialog_width = 414; private static final int dialog_height = 340; private static final int dialog_height_extend = 573; / ** * Lancez l'application. * / public static void main (String [] args) {try {org.jb2011.lnf.beautyeye.beautyeyelnfhelper.launchBeautyEyelnf (); } catch (exception e) {// TODO Exception System.out.println ("Chargement de la peau colorée a échoué!"); } try {logInDialog Dialog = new LogInDialog (); Dialog.setDefaultCloseOperation (jdialog.dispose_on_close); Dialog.setVisible (true); } catch (exception e) {e.printStackTrace (); }} / ** * Créez la boîte de dialogue. * / public LogIndialog () {setalwaySontop (true); setResizable (false); SetBounds (400, 100, Dialog_Width, Dialog_Height); getContentPane (). setLayout (new BorderLayout ()); ContentPanel.SetBorder (New videBorder (5, 5, 5, 5)); getContentPane (). Add (contentPanel, borderLayout.Center); contentPanel.SetLayout (null); // setCenter // setLocation (windowXy.getXy (logIndialog.This.getSize ())); JBUTTON BTNNEWBUTTON = NOUVEAU JBUTTON ("REGISTRE"); btnnewbutton.addactionListener (new ActionListener () {public void ActionPerformed (actionevent arg0) {if (logInDialog.this.getheight () == Dialog_Height_Extend) {logindialog.this.setSize (Dialog_Width, Dialog_height);} else { LogIndialog.This.SetSize (Dialog_Width, Dialog_Height_Extend);}}}); btnnewbutton.setbounds (53, 224, 93, 23); contentPanel.add (btnnewbutton); JBUTTON BTNNEWBUTTON_1 = NOUVEAU JBUTTON ("Login"); btnnewbutton_1.setbounds (190, 224, 93, 23); contentPanel.add (btnnewbutton_1); TextField = new JTextField (); TextField.SetBounds (133, 147, 150, 25); contentPanel.add (TextField); TextField.SetColumns (10); TextField_1 = new JTextField (); TextField_1.setBounds (133, 182, 150, 25); contentPanel.add (TextField_1); TextField_1.setColumns (10); JLabel lblNewLabel = new JLabel ("Mailbox"); lblnewLabel.setbounds (53, 151, 54, 15); ContentPanel.add (LBLNewLabel); JLabel lblnewLabel_1 = new JLabel ("mot de passe"); lblnewLabel_1.setbounds (53, 194, 54, 15); contentPanel.add (lblnewLabel_1); JLabel lblNewLabel_2 = new JLabel ("New Label"); LBLNEWLABEL_2.SetBounds (0, 0, 360, 136); ImageIcon icon = new ImageIcon (logIndialog.class.getResource ("/ res / login.jpg")); icon = imagescale.getImage (icon, lblnewLabel_2.getWidth (), lblnewLabel_2.getheight ()); lblnewLabel_2.seticon ((icône)); contentPanel.add (lblnewLabel_2); Jpanel Panel = new JPanel (); PANNEL.SETBORDER (NOUVEAU TITLEDBLEBER (NULL, "/ U6CE8 / U518C / U7528 / U6237", TitledBorder.Leading, TitledBorder.Top, NULL, NULL)); Panel.SetBounds (12, 259, 336, 221); contentPanel.add (panneau); PANNEL.SETLAYOUT (NULL); JLabel lblnewLabel_3 = new JLabel ("e-mail"); LBLNEWLABEL_3.SetBounds (41, 29, 55, 18); PANNEL.ADD (LBLNEWLABEL_3); JLabel lblnewLabel_4 = new JLabel ("Code de vérification"); LBLNEWLABEL_4.SetBounds (41, 85, 55, 18); PANNEL.ADD (LBLNEWLABEL_4); JLabel lblnewLabel_5 = new JLabel ("mot de passe"); LBLNEWLABEL_5.SetBounds (41, 115, 55, 18); PANNEL.ADD (LBLNEWLABEL_5); JLABEL Label = new JLabel ("Confirmer le mot de passe"); Label.SetBounds (41, 145, 55, 18); panneau.add (étiquette); TextField_2 = new JTextField (); TextField_2.SetBounds (123, 22, 150, 25); PANNEL.ADD (TextField_2); TextField_2.SetColumns (10); TextField_3 = new JTextField (); TextField_3.SetBounds (123, 80, 150, 25); PANNEL.ADD (TextField_3); TextField_3.SetColumns (10); TextField_4 = new JTextField (); TextField_4.SetBounds (123, 113, 150, 25); PANNEL.ADD (TextField_4); TextField_4.SetColumns (10); TextField_5 = new JTextField (); TextField_5.SetBounds (123, 113, 150, 25); PANNEL.ADD (TextField_4); TextField_4.SetColumns (10); TextField_5 = new JTextField (); TextField_5.SetBounds (123, 145, 150, 25); PANNEL.ADD (TextField_5); TextField_5.SetColumns (10); JBUTTON BTNNEWBUTTON_2 = NOUVEAU JBUTTON ("Envoyer le code de vérification"); btnnewbutton_2.setbounds (123, 52, 83, 23); PANNEL.ADD (BTNNEWBUTTON_2); JBUTTON BTNNEWBUTTON_3 = NOUVEAU JBUTTON ("Annuler"); BTNNewButton_3.SetBounds (51, 182, 83, 27); PANNEL.ADD (BTNNEWBUTTON_3); JBUTTON BTNNEWBUTTON_4 = NOUVEAU JBUTTON ("Confirmer"); btnnewbutton_4.setbounds (190, 182, 83, 27); PANNEL.ADD (BTNNEWBUTTON_4); }}Classe d'outils com.lsh.util.imagescale
package com.lsh.util; import java.awt.image; import javax.swing.imageicon; public class ImagesCale {public static ImageIcon getImage (ImageIcon icon, int larget, int height) {image image = icon.getImage (). GetScalEdInstance (largeur, hauteur, image_replicate); icon.setimage (image); Icône de retour; }}Classe d'outils com.lsh.util.windowxy
package com.lsh.util; importer java.awt.dimension; import java.awt.point; import java.awt.toolkit; public class windowXy {public static point getxy (int w, int h) {toolkit toolkit = toolkit.getdefaulttoolkit (); int width = toolkit.getScreenSize (). largeur; int height = toolkit.getScreenSize (). hauteur; retourner nouveau point ((largeur-w) / 2, (hauteur-h) / 2); } public static point getXy (dimension dimension) {return getXy (dimension.width, dimension.height); }}Ce qui précède est tout le contenu de cet article. J'espère que cela sera utile à l'apprentissage de tous et j'espère que tout le monde soutiendra davantage Wulin.com.