1215沒看牙齒的日子

 

原本 今天要去看牙齒的

但沒去看牙齒

 

一來自己害怕看牙醫

二來自己害怕沒有錢

 

所以沒去看牙齒

 

坦白說,我真的很膽小

膽小到甚麼事好像都做不好

 

但是... 就算如此膽小的我

卻仍是對未來有憧憬

 

所以那怕看牙齒

那怕未來有許多的恐懼和害怕

一樣還是會選擇面對吧

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class JFrame7_3 {
  JFrame f;
  public static void main(String argv[]) {
    new JFrame7_3(); 
    }
  public JFrame7_3() {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true)
    f=new JFrame("JFrame 7-3");
    f.setBounds(0,0,400,300);
    f.setVisible(true);


    f.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    f.addWindowListener(new WindowAdapter() {
     

public void windowClosing(WindowEvent e) {
        int result=JOptionPane.showConfirmDialog(f,   //或用 (Component)e.getSource() 亦可
                   "確定要結束程式嗎?",
                   "確認訊息",
                   JOptionPane.YES_NO_OPTION,
                   JOptionPane.WARNING_MESSAGE);
        if (result==JOptionPane.YES_OPTION) {System.exit(0);}
//在構面裡建立對話框   

    }   
      });
    }
  }

java建立基本的構面:20181207

 

 

//建立構面之前要先加入awt和swing的相關資料庫

//建立框架步驟:建立框架→建立框架的函式→建立函式內容

 

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JFrame1 {
JFrame f; //建立框架

public static void main(String argv[]) {
new JFrame1(); //建立框架的函式
}
public JFrame1() { //建立函示內容
f=new JFrame("JFrame 1"); //建立框架的名稱
f.setBounds(0,0,400,300); //建立框架的大小
f.setVisible(true); //將框架可視覺化
}
}

PracticeJava20181201Listener


package MyFrame;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class MyFrame extends JFrame{
// 此視窗所用到的元件
int fieldWidth = 10;
JPanel panel, inPanel, outPanel;
JLabel inputFieldLabel, outputFieldLabel;
JTextField inputField, outputField;
JButton inputButton;

public MyFrame() {
super("視窗事件範例");//為什麼子類別可以繼承這個範例?這範例從哪來的?
initApp();
}

// 元件相關設置
public void initApp() {
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
//BoxLayout是讓物件保持水平或垂直平行對齊的語法
inPanel = new JPanel();
outPanel = new JPanel();

inputFieldLabel = new JLabel("輸入文字");
inputField = new JTextField(fieldWidth);
inputField.addActionListener(new inputFieldActionListener()); // 要將事件處理加入

inputButton = new JButton("確定");
inputButton.addActionListener(new inputButtonActionListener()); // 要將事件處理加入

outputFieldLabel = new JLabel("輸出文字");
outputField = new JTextField(fieldWidth);

panel.add(inputFieldLabel);
panel.add(inputField);
panel.add(outputFieldLabel);
panel.add(outputField);

inPanel.add(inputFieldLabel);
inPanel.add(inputField);
inPanel.add(inputButton);
outPanel.add(outputFieldLabel);
outPanel.add(outputField);

panel.add(inPanel);
panel.add(outPanel);

this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 300);
this.getContentPane().add(panel);
this.setVisible(true);
}

// inputField的事件處理
private class inputFieldActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
changeOutputText();
}
}

// inputButton的事件處理
private class inputButtonActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
changeOutputText();
}
}

public void changeOutputText() {
String input_field_str = inputField.getText();
outputField.setText(input_field_str);
}

public static void main(String[] args) {
MyFrame app = new MyFrame();
}
}