この記事では、参照用のスイングログイン登録インターフェイスに表示される特定のコードを共有します。特定のコンテンツは次のとおりです
開発環境: Eclipse Neon.3リリース(4.6.3)
Javaeeバージョンを使用しています。インターフェイスの設計を容易にするために、市場で直接検索できるWindowbuilderプラグインをインストールする必要があります。
説明:Kaigeのビデオを参照して、同期して学習します
インターフェイス効果
ログインインターフェイス
登録インターフェイス
重要なテクノロジー
このプロジェクトでは、Java Swing Surped Plug-inを使用して写真を使用します(SRCをクリックしてフォルダーを右クリックしてRESに名前を付け、画像login.jpgをコピーします)
ソースコード
com.lsh.view.logindialog
パッケージcom.lsh.view; Import java.awt.borderlayout; import javax.swing.jbutton; import javax.swing.jdialog; import javax.swing.jpanel; import javax.swing.border.emptyborder; import javax.swing.jtextfield; import.swing.swing.swing.swing java.awt.event.actionlistener; Import java.awt.event.actionevent; Import javax.swing.imageicon; Import javax.swing.border.titledborder; import com.lsh.util.imagescale; jpanel();プライベートJTextfield Textfield;プライベートJTextField Textfield_1;プライベートJTextField Textfield_2;プライベートJTextField Textfield_3;プライベートJTextField Textfield_4;プライベート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; /***アプリケーションを起動します。 */ public static void main(string [] args){try {org.jb2011.lnf.beautyey.beautyeyelnfhelper.launchbeautyeyelnf(); } catch(Exception e){// Todo Exception System.out.println( "カラフルな肌のロードが失敗!"); } try {logindialogダイアログ= new logindialog(); Dialog.setDefaultCloseoperation(jdialog.dispose_on_close); dialog.setVisible(true); } catch(Exception e){e.printstacktrace(); }} /***ダイアログを作成します。 */ public logindialog(){setalwaysontop(true); setSresizable(false); setbounds(400、100、dialog_width、dialog_height); getContentPane()。setLayout(new borderlayout()); contentPanel.setborder(新しいemptyborder(5、5、5、5)); getContentPane()。add(contentSpanel、borderlayout.center); ContentPanel.setLayout(null); // setCenter // setLocation(windowxy.getXy(logindialog.this.getSize())); jbutton btnnewbutton = new jbutton( "Register"); btnnewbutton.AddActionListener(new ActionListener(){public void ActionPerformed(ActionEvent Arg0){if(logindialog.this.getheight()== dialog_height_extend){logindialog.this.setsize(dialog_width、dialog_height);} logindialog.this.setsize(dialog_width、dialog_height_extend); btnnewbutton.setbounds(53、224、93、23); ContentPanel.Add(btnnewbutton); jbutton btnnewbutton_1 = new 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( "Password"); 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 = ImagesScale.GetImage(ICON、LBLNEWLABEL_2.GETWIDTH()、LBLNEWLABEL_2.GETHEIGHT()); lblnewlabel_2.seticon((icon)); contentPanel.Add(lblnewlabel_2); jpanelパネル= new JPanel(); panel.setborder(new Titledborder(null、 "/u6ce8/u518c/u7528/u6237"、wedborder.Leading、withedborder.top、null、null)); panel.setbounds(12、259、336、221); ContentPanel.Add(パネル); panel.setlayout(null); jlabel lblnewlabel_3 = new Jlabel( "email"); lblnewlabel_3.setbounds(41、29、55、18); panel.add(lblnewlabel_3); Jlabel lblnewlabel_4 = new Jlabel( "検証コード"); lblnewlabel_4.setbounds(41、85、55、18); panel.add(lblnewlabel_4); jlabel lblnewlabel_5 = new Jlabel( "Password"); lblnewlabel_5.setbounds(41、115、55、18); panel.add(lblnewlabel_5); Jlabel label = new Jlabel( "Passwordの確認"); label.setbounds(41、145、55、18); panel.add(label); textfield_2 = new jtextfield(); textfield_2.setbounds(123、22、150、25); panel.add(textfield_2); textfield_2.setColumns(10); textfield_3 = new jtextfield(); textfield_3.setbounds(123、80、150、25); panel.add(textfield_3); textfield_3.setColumns(10); textfield_4 = new jtextfield(); textfield_4.setbounds(123、113、150、25); panel.add(textfield_4); textfield_4.setColumns(10); textfield_5 = new jtextfield(); textfield_5.setbounds(123、113、150、25); panel.add(textfield_4); textfield_4.setColumns(10); textfield_5 = new jtextfield(); textfield_5.setbounds(123、145、150、25); panel.add(textfield_5); textfield_5.setColumns(10); jbutton btnnewbutton_2 = new jbutton( "検証コードを送信"); btnnewbutton_2.setbounds(123、52、83、23); panel.add(btnnewbutton_2); jbutton btnnewbutton_3 = new jbutton( "キャンセル"); btnnewbutton_3.setbounds(51、182、83、27); panel.add(btnnewbutton_3); jbutton btnnewbutton_4 = new jbutton( "Confism"); btnnewbutton_4.setbounds(190、182、83、27); panel.add(btnnewbutton_4); }}ツールクラスcom.lsh.util.imagescale
パッケージcom.lsh.util;インポートjava.awt.image;インポートjavax.swing.imageicon; public class imagescale {public static imageicon getimage(ImageIcon Icon、int width、int height){image image = icon.getimage()。 icon.setImage(画像);返品アイコン; }}ツールクラスcom.lsh.util.windowxy
パッケージcom.lsh.util;インポートjava.awt.dimension; Import java.awt.point; Import java.awt.toolkit; public static point getxy(int w、h){toolkit toolkit = toolkit.getDefaultToolkit(); int width = toolkit.getScreensize()。width; int height = toolkit.getScreensize()。高さ;新しいポイント((width-w)/2、(height-h)/2)を返します。 } public static point getXy(dimension dimension){return getXy(dimension.width、dimension.height); }}上記はこの記事のすべての内容です。みんなの学習に役立つことを願っています。誰もがwulin.comをもっとサポートすることを願っています。