?? jappletframe.java
字號:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import java.net.*;
public class JAppletFrame extends JApplet{
JPanel jPanel1 = new JPanel();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JButton jButton1 = new JButton();
JPanel jPanel2 = new JPanel();
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
GridLayout gridLayout1 = new GridLayout();
JScrollPane jScrollPane1 = new JScrollPane();
JTextArea jTextArea1 = new JTextArea();
URL url;
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
AppletContext appletContext;
//建構函數
public JAppletFrame() {
}
//初始化
public void init() {
try {
myInit();
}
catch(Exception e) { //異常處理
e.printStackTrace();
}
}
//組件初始設定
private void myInit() throws Exception {
this.setSize(new Dimension(400, 300));
this.getContentPane ().setLayout(new BorderLayout(5,5));
jLabel1.setText("URL:");
jTextField1.setPreferredSize(new Dimension(250, 23));
jButton1.setText("搜尋");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jButton2.setText("功能一");
jButton3.setText("功能二");
jPanel2.setLayout(gridLayout1);
gridLayout1.setColumns(1);
gridLayout1.setHgap(5);
gridLayout1.setRows(6);
gridLayout1.setVgap(5);
jButton4.setText("功能三");
jButton5.setText("功能四");
this.getContentPane().add(jPanel2, BorderLayout.WEST);
jPanel2.add(jButton2, null);
jPanel2.add(jButton3, null);
jPanel2.add(jButton4, null);
jPanel2.add(jButton5, null);
this.getContentPane().add(jScrollPane1, BorderLayout.CENTER);
this.getContentPane().add(jPanel1, BorderLayout.NORTH);
jPanel1.add(jLabel1, null);
jPanel1.add(jTextField1, null);
jPanel1.add(jButton1, null);
jScrollPane1.getViewport().add(jTextArea1, null);
}
//啟動applet
public void start() {
}
//停止applet
public void stop() {
}
//釋放applet資源
public void destroy() {
}
//取得Applet信息
public String getAppletInfo() {
return "Applet Information";
}
//取得parameter
public String[][] getParameterInfo() {
return null;
}
//Application的main()
public static void main(String[] args) {
JAppletFrame applet = new JAppletFrame();
JFrame frame = new JFrame();
frame.setTitle("JApplet與JFrame的合并");
frame.getContentPane().add(applet, BorderLayout.CENTER);//將Applet加入到frame中
applet.init();
applet.start();
frame.setSize(400,320);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
void jButton1_actionPerformed(ActionEvent e) {
try{
showStatus("");
url=new URL(jTextField1.getText ());
jTextArea1.append ("搜尋網址--"+"\n");
jTextArea1.append (jTextField1.getText ()+"\n");
showStatus("搜尋網址中");
}catch (MalformedURLException urle)
{
showStatus("輸入網址錯誤");
jTextArea1.append ("錯誤信息--"+"\n");
jTextArea1.append (urle.toString ()+"\n");
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -