JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區 » Swing/AWT/SWT/JFace  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 有人用過Tcl-JAVA嗎?
hans_wu





發文: 1
積分: 0
於 2018-08-23 23:34 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
參考來源:
http://tcljava.sourceforge.net/docs/website/matchmadeforscripting.html

範例程式:
Java source code--
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import java.awt.Button;
import java.awt.Frame;
 
public class TestAWT {
    public static void main(String[] argv) {
        Frame f = new Frame();
        Button b = new Button("Press Me");
        f.setSize(300,300);
        f.add(b);
        f.show();
    }
}
 


Tcl-Java source code--
1
2
3
4
5
6
7
8
9
10
11
12
package require java
java::import java.awt.Button
java::import java.awt.Frame
 
set f [java::new Frame]
set b [java::new Button "Press Me"]
 
$f setSize 300 300
$f add $b
$f show
 


問題來了!前面這些我都懂,下面Java source code程式碼怎麼改寫為Tcl-Java,有
先進可以給個起手勢嗎?想說蠻有新奇的語法,所以拿別人的程式碼看先進怎麼改?好便
於學習。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
public class treedb extends JFrame {
  private JDesktopPane jdesktop; // JDesktopPane物件變數
 
  private String dsn = "Books"; // ODBC系統資料來源
 
  private String user = ""; // 使用者帳號
 
  private String pass = ""; // 密碼
 
  // 新增,更新,刪除,查詢資料內層視窗的物件變數
  private static JInternalFrame addStudent111Frame = null;
  private static JInternalFrame addBook112Frame = null;
  private static JInternalFrame addBrview113Frame = null;
 
  private static JInternalFrame fix1Frame = null;
  private static JInternalFrame fix2Frame = null;
 
  private static JInternalFrame up1Frame = null;
  private static JInternalFrame up2Frame = null;
 
  private static JInternalFrame del1Frame = null;
  private static JInternalFrame del2Frame = null;
 
  private JTree tree;
  private JTextField JTF;
  private DefaultMutableTreeNode x,x111,x112,x113,x121,x122,x131,x132,x141,x142;
 
  public treedb() {
    super("資料庫報告"); // 視窗標題
    int offset = 100;
    // 取得螢幕的尺寸
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    // 設定視窗範圍
    setBounds(offset, offset, screenSize.width - offset * 2,
        screenSize.height - offset * 2);
    set_ui_look_and_feel();
    makeGUI();
    JDBC.openODBC(dsn, user, pass); // 開啟JDBC
  }
 
  private void set_ui_look_and_feel()
  {
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    SwingUtilities.updateComponentTreeUI(this);
    }
    catch(Exception ex){
    }
  }
 
  public void init() {
    try {
      SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
          makeGUI();
        }
      });
    }
    catch (Exception exc) {
      System.out.println("無法創造" + exc);
    }
  }
 
  private void makeGUI() {
    setLayout(new BorderLayout());
 
    DefaultMutableTreeNode top = new DefaultMutableTreeNode("簡易圖書管理系統");
    // 建立樹根
    x = new DefaultMutableTreeNode("jdbc:odbc:Books.mdb");
    top.add(x);
    DefaultMutableTreeNode x1 = new DefaultMutableTreeNode("JAVA_DB");
    x.add(x1);
 
    DefaultMutableTreeNode x11 = new DefaultMutableTreeNode("新增");
    x1.add(x11);
 
    x111 = new DefaultMutableTreeNode("借書人資料");
    x11.add(x111);
 
    x112 = new DefaultMutableTreeNode("圖書資料");
    x11.add(x112);
 
    x113 = new DefaultMutableTreeNode("借書單資料");
    x11.add(x113);
 
    DefaultMutableTreeNode x12 = new DefaultMutableTreeNode("查詢");
    x1.add(x12);
 
    x121 = new DefaultMutableTreeNode("書籍查詢");
    x12.add(x121);
 
    x122 = new DefaultMutableTreeNode("學生借閱資料");
    x12.add(x122);
 
    DefaultMutableTreeNode x13 = new DefaultMutableTreeNode("更新");
    x1.add(x13);
 
    x131 = new DefaultMutableTreeNode("學生資料");
    x13.add(x131);
 
    x132 = new DefaultMutableTreeNode("借閱資料");
    x13.add(x132);
 
    DefaultMutableTreeNode x14 = new DefaultMutableTreeNode("刪除");
    x1.add(x14);
 
    x141 = new DefaultMutableTreeNode("學生資料");
    x14.add(x141);
 
    x142 = new DefaultMutableTreeNode("借閱資料");
    x14.add(x142);
 
    tree = new JTree(top);
    // 建立數Tree的結構
 
    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane JSP = new JScrollPane(tree, v, h);
    add(JSP, BorderLayout.WEST);
 
    JTF = new JTextField("", 20);
    add(JTF, BorderLayout.SOUTH);
    tree.addMouseListener(new MouseAdapter() {
      public void mouseClicked(MouseEvent me) {
        doMouseClicked(me);
      }
    });
 
    jdesktop = new JDesktopPane();
    getContentPane().add(jdesktop);
  }
 
  void doMouseClicked(MouseEvent me) {
    final TreePath path = tree.getPathForLocation(me.getX(), me.getY());
    if (path != null && me.getClickCount() == 2) {
      Object node = path.getLastPathComponent();
     {
      if (node == x111) {
        createInternalFrame(1);
      }
      else if (node == x112) {
        createInternalFrame(2);
      }
      else if (node == x113) {
        createInternalFrame(3);
      }
      else if (node == x121) {
        createInternalFrame(4);
      }
      else if (node == x122) {
        createInternalFrame(5);
      }
      else if (node == x131) {
        createInternalFrame(6);
      }
      else if (node == x132) {
        createInternalFrame(7);
      }
      else if (node == x141) {
        createInternalFrame(8);
      }
      else if (node == x142) {
        createInternalFrame(9);
      }
     }
    }
 
    if (path != null)
      JTF.setText(path.toString());
    else
      JTF.setText("");
  }
 
  // 建立與顯示內層視窗
  private void createInternalFrame(int type) {
    JInternalFrame iframe = null;
    // 開啟各種功能的內層視窗
    switch (type) {
      case 1: // 開啟新增資料視窗1~3
        if (addStudent111Frame == null) {
          addStudent111Frame = new TBStudent();
        }
        iframe = addStudent111Frame;
        break;
 
      case 2:
        if (addBook112Frame == null) {
          addBook112Frame = new TBBook();
        }
        iframe = addBook112Frame;
        break;
 
      case 3:
        if (addBrview113Frame == null) {
          addBrview113Frame = new TBBB();
        }
        iframe = addBrview113Frame;
        break;
 
      case 4: // 開啟查詢資料視窗4~5
        if (fix1Frame == null) {
          fix1Frame = new TB02();
        }
        iframe = fix1Frame;
        break;
 
      case 5:
        if (fix2Frame == null) {
          fix2Frame = new TB03();
        }
        iframe = fix2Frame;
        break;
 
      case 6: // 開啟更新資料視窗6~7
        if (up1Frame == null) {
          up1Frame = new TB04();
        }
        iframe = up1Frame;
        break;
      case 7:
        if (up2Frame == null) {
          up2Frame = new TB05();
        }
        iframe = up2Frame;
        break;
      case 8: // 開啟刪除資料視窗8~9
        if (del1Frame == null) {
          del1Frame = new TB06();
        }
        iframe = del1Frame;
        break;
      case 9:
        if (del2Frame == null) {
          del2Frame = new TB07();
        }
        iframe = del2Frame;
        break;
    }
    if (!iframe.isVisible()) {
      jdesktop.add(iframe);
      iframe.setVisible(true); // 顯示內層視窗
    }
    else {
      try {
        iframe.setSelected(true); // 顯示成啟動視窗
        if (iframe.isIcon()) // 不是圖示顯示
          iframe.setIcon(false);
      }
      catch (PropertyVetoException e) {
        e.printStackTrace();
      }
    }
  }
 
  public static void main(String[] args) { // 建立Swing應用程式
    treedb app = new treedb();
    app.setDefaultCloseOperation(EXIT_ON_CLOSE);
    app.setSize(800,600);
    app.setVisible(true); // 顯示視窗
  }
 


reply to postreply to post
作者 Re:有人用過Tcl-JAVA嗎? [Re:hans_wu]
qrtt1





發文: 1747
積分: 31
於 2018-08-24 09:29 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
一般來說,不太會選擇一個死寂的專案來使用。
你是有什麼苦衷呢?


reply to postreply to post
蝸牛角上爭何事?石火光中寄此身,隨富隨貧且歡樂,不開口笑是癡人。
my notes
» JWorld@TW »  Java SE 討論區 » Swing/AWT/SWT/JFace

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8