欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

情人節(jié)寫給女朋友Java Swing代碼程序

 更新時(shí)間:2018年02月12日 10:38:47   作者:阿笨爹  
這篇文章主要為大家分享了情人節(jié)寫給女朋友的java小程序,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,祝大家每天都是情人節(jié)

馬上又要到情人節(jié)了,再不解風(fēng)情的人也得向女友表示表示。作為一個(gè)程序員,示愛的時(shí)候自然也要用我們自己的方式。

這里給大家上傳一段我在今年情人節(jié)的時(shí)候?qū)懡o女朋友的一段簡(jiǎn)單的Java Swing代碼,主要定義了一個(gè)對(duì)話框,讓女友選擇是不是喜歡自己。如果她選了“是”,皆大歡喜,如果她想選“不”,哼哼。。??匆幌陆貓D吧。

代碼效果圖:


接下來不廢話,直接上代碼了。新版本已上傳,也歡迎大家到我的github上下載和改進(jìn)代碼(點(diǎn)此轉(zhuǎn)到github)。

另外就是因?yàn)檫@個(gè)代碼當(dāng)時(shí)是在情人節(jié)的時(shí)候?qū)懙?,?duì)話框標(biāo)題欄的信息也是與情人節(jié)相關(guān),要想在其他的節(jié)日使用,只需要修改幾個(gè)字符串就可以了,我在需要修改的地方都打了中文注釋,大家可以很容易地找到。不過正如我在注釋里寫的那樣,這個(gè)程序頂多是你倆之間一個(gè)溫馨的小玩笑,你要是想今晚嘿嘿嘿的話,真正的禮物還是得備好哦: )

package gift_package; 
 
 
import java.awt.Container; 
import java.awt.Font; 
import java.awt.Toolkit; 
import java.awt.event.MouseEvent; 
import java.awt.event.MouseListener; 
import java.awt.event.WindowEvent; 
import java.awt.event.WindowListener; 
 
 
import javax.swing.JButton; 
import javax.swing.JDialog; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.SwingConstants; 
import javax.swing.WindowConstants; 
 
 
/** 
 * A funny code for your lover, which creates a frame that let her/him choose 
 * whether she/he loves you. If she/he choose 'YES', everythingis normal, but 
 * if she/he tries to choose 'NO', something interestingwould happen. First, 
 * the 'NO' button would change its position, it lookes like it attemps to escape 
 * from being clicked. After a couple of rounds, if she/he still want to click 
 * 'NO' button, the 'NO' button and 'YES' button will exchange their position. 
 * Besides, the window will cannot be closed untill the 'YES' button is clicked. 
 * 
 * To use this code, please make sure her/his computer has installed the JRE. 
 * 
 * Note that this code is just a little joke, DO NOT USE IT AS A REAL VALENTIN'S 
 * DAY GIFT, if you want to get laid at Valentin's Day, use ROSE, WINE and FANCY 
 * RESTAURANT, if you want to keep your mate's love, use YOUR HEART. 
 * 
 * @author rainman_zjd 
 * @version initialt version, 2016.3.20 
 */ 
public class HappyValentinsDay extends JFrame { 
 
 
  private static final long serialVersionUID = 1L; 
 
 
  private JLabel   label; 
  private JButton  button1; 
  private JButton  button2; 
  private JDialog  dialog1; 
 
 
  private int enterCount = 0; 
  private boolean chooseFlag = false; 
 
 
  public static final int screenWidth =  
      (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth(); 
  public static final int screenHeight =  
      (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight(); 
 
 
  public HappyValentinsDay() { 
    label  = new JLabel("Hi, my name is rainman_zjd, I love you, do you love me?", SwingConstants.CENTER); // 自行修改 
    button1 = new JButton("No, I don't!"); // 按鈕1 
    button2 = new JButton("Yes, I do!");  // 按鈕2 
    dialog1 = new JDialog(this);      // 創(chuàng)建一個(gè)新的對(duì)話框,并設(shè)置父窗口為當(dāng)前窗體 
    windowInitial(); 
    setWindowListener(); 
  }// constructor 
 
 
  public HappyValentinsDay(String labelTxt, String bt1Txt, String bt2Txt) { 
    label  = new JLabel(labelTxt, SwingConstants.CENTER); 
    button1 = new JButton(bt1Txt); 
    button2 = new JButton(bt2Txt); 
    dialog1 = new JDialog(this); 
    windowInitial(); 
    chooseFlag = true; 
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
    setVisible(true); 
  }// constructor_String 
 
 
  /** 
   * 窗體初始化,使用的是絕對(duì)布局 
   */ 
  private void windowInitial() { 
    setDialog(dialog1, "Awesome!", "Meeting you is the luckest thing in my life!"); // 自行修改 
 
 
    label.setFont(new Font("", Font.BOLD, 17)); 
    label.setBounds(0, 30, 480, 20); 
     
    /** 
     * 以匿名內(nèi)部類的方式為按鈕1添加鼠標(biāo)事件監(jiān)聽器,當(dāng)鼠標(biāo)進(jìn)入按鈕1后將突然改變自己的位置 
     */ 
    button1.addMouseListener(new MouseListener() {  
      @Override 
      public void mouseReleased(MouseEvent e) {return;}       
      @Override 
      public void mousePressed(MouseEvent e) {return;}       
      @Override 
      public void mouseExited(MouseEvent e) {return;}       
      @Override 
      public void mouseEntered(MouseEvent e) { 
        switch(enterCount) { 
        case 0: 
          button1.setBounds(75, 60, 110, 30); 
          HappyValentinsDay.this.repaint(); 
          ++enterCount; 
          break; 
        case 1: 
          button1.setBounds(75, 110, 110, 30); 
          HappyValentinsDay.this.repaint(); 
          ++enterCount; 
          break; 
        case 2: 
          button1.setBounds(155, 60, 110, 30); 
          HappyValentinsDay.this.repaint(); 
          ++enterCount; 
          break; 
        case 3: 
          button1.setBounds(75, 110, 110, 30); 
          HappyValentinsDay.this.repaint(); 
          ++enterCount; 
          break; 
        case 4: 
          button1.setBounds(310, 110, 110, 30); 
          button2.setBounds(75, 110, 110, 30); 
          HappyValentinsDay.this.repaint(); 
          ++enterCount; 
          break; 
        case 5: 
          button1.setBounds(75, 110, 110, 30); 
          button2.setBounds(310, 110, 110, 30); 
          HappyValentinsDay.this.repaint(); 
          enterCount = 0; 
          break; 
        }// seitch_entercount 
      }// mouseEntered       
      @Override 
      public void mouseClicked(MouseEvent e) { 
        dialog1.setVisible(true); 
        setDefaultCloseOperation(DISPOSE_ON_CLOSE); 
      }// mouseClicked 
    });// MouseListener 
     
    button1.setBounds(70, 110, 110, 30); 
    button1.setFont(new Font("", Font.BOLD, 13)); 
     
    /** 
     * 以匿名內(nèi)部類的方式為按鈕2添加鼠標(biāo)事件監(jiān)聽器,按下時(shí)顯示對(duì)話框 
     */ 
    button2.addMouseListener(new MouseListener() {    
      @Override 
      public void mouseReleased(MouseEvent e) {return;}       
      @Override 
      public void mousePressed(MouseEvent e) {return;}       
      @Override 
      public void mouseExited(MouseEvent e) {return;}       
      @Override 
      public void mouseEntered(MouseEvent e) {return;}       
      @Override 
      public void mouseClicked(MouseEvent e) { 
        dialog1.setVisible(true); 
        chooseFlag = true; 
        setDefaultCloseOperation(DISPOSE_ON_CLOSE); 
      }// mouseClicked 
    });// MouseListener 
    button2.setBounds(310, 110, 110, 30); 
    button2.setFont(new Font("", Font.BOLD, 13)); 
 
 
    Container c = getContentPane(); 
    c.setLayout(null); 
    c.add(label); 
    c.add(button1); 
    c.add(button2); 
    setTitle("Happy Valentin's Day!"); // 自行修改 
    setBounds(screenWidth/2-250, screenHeight/2-100, 500, 200); 
    setResizable(false); 
    setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 
  }// windowInitial 
 
 
  /** 
   * 設(shè)置對(duì)話框?qū)傩?
   * @param diag 
   * @param tittle 
   * @param txt 
   */ 
  private void setDialog(JDialog diag, String tittle, String txt) { 
    JLabel diagLabel = new JLabel(txt, SwingConstants.CENTER); 
    diagLabel.setFont(new Font("", Font.BOLD, 17)); 
    diagLabel.setBounds(0, 40, 430, 20); 
    JButton diagBut = new JButton("Confirm"); 
    diagBut.setFont(new Font("", Font.BOLD, 14)); 
    diagBut.setBounds(155, 100, 100, 30); 
    diagBut.addMouseListener(new MouseListener() {       
      @Override 
      public void mouseReleased(MouseEvent e) {return;}             
      @Override 
      public void mousePressed(MouseEvent e) {return;}             
      @Override 
      public void mouseExited(MouseEvent e) {return;}            
      @Override 
      public void mouseEntered(MouseEvent e) {return;}      
      @Override 
      public void mouseClicked(MouseEvent e) { 
        diag.dispose(); 
        if (chooseFlag) 
          System.exit(0); 
      }// mouseClicked 
    }); 
    diag.setTitle(tittle); 
    diag.setBounds(screenWidth/2-225, screenHeight/2-100, 450, 200); 
    diag.setLayout(null); 
    diag.add(diagBut); 
    diag.add(diagLabel); 
  }// setDialog 
  /** 
   * 設(shè)置單擊窗口關(guān)閉按鈕時(shí)的動(dòng)作 
   */ 
  private void setWindowListener() { 
    this.addWindowListener(new WindowListener() {       
      @Override 
      public void windowOpened(WindowEvent e) {return;}      
      @Override 
      public void windowIconified(WindowEvent e) {return;}       
      @Override 
      public void windowDeiconified(WindowEvent e) {return;} 
      @Override 
      public void windowDeactivated(WindowEvent e) {return;} 
      @Override 
      public void windowClosed(WindowEvent e) {return;}      
      @Override 
      public void windowActivated(WindowEvent e) {return;} 
      @Override 
      public void windowClosing(WindowEvent e) { 
        if(!chooseFlag) { 
          String labelTxt = "Is your default choose \"Yes, I do!\"?"; // 自行修改 
          new HappyValentinsDay(labelTxt, "NO", "YES"); 
        }// if 
      }// windowClosing 
    });// WindowListener 
  }// setWindowListener 
 
 
  public static void main(String[] args) { 
    HappyValentinsDay myApp = new HappyValentinsDay(); 
    myApp.setVisible(true); 
  }// main 
 
 
}/*HappyValentinsDay*/ 

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家,祝大家情人節(jié)快樂

相關(guān)文章

最新評(píng)論