【JAVA】简单按钮,输入,输出界面——Crawler界面

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.*;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

public class Crawler extends JFrame {
public static final int BOARD_WIDTH = 540;
public static final int BOARD_HEIGHT = 570;
public static final int X_LOCATION = 100;
public static final int Y_LOCATION = 50;

//把节目分为上中三个Panel
JPanel northPanel = new JPanel();
JPanel centerPanel
= new JPanel();
JPanel southPanel
= new JPanel();

//输入
JTextField txtField = new JTextField(30);
JLabel labelURL
= new JLabel("Starting URL: ", JLabel.RIGHT);
//输出
JTextArea txtArea = new JTextArea(10,40);
JLabel labelTxt
= new JLabel("Result");

//按钮
JButton startButton = new JButton("start");
JButton cancelButton
= new JButton("cancel");



public void launchFrame() throws Exception{
//界面初始化
this.setLocation(X_LOCATION, Y_LOCATION);
this.setSize(BOARD_WIDTH, BOARD_HEIGHT);
this.setResizable(false);
this.setVisible(true);
this.setLayout(new GridLayout(3,1)); //总体为三行一列布局
this.add(northPanel);
this.add(centerPanel);
this.add(southPanel);

northPanel.add(labelURL);
northPanel.add(txtField);
centerPanel.setLayout(
new FlowLayout());
centerPanel.add(labelTxt);
centerPanel.add(txtArea);
southPanel.setLayout(
new FlowLayout());
southPanel.add(startButton);
southPanel.add(cancelButton);

startButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
String url
= txtField.getText();
txtArea.append(url
+"\n");
}
});
cancelButton.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
txtArea.setText(
"");
}
});
this.addWindowListener(new WindowAdapter(){
public void windowClosing (WindowEvent e){
System.exit(
0);
}
});
}

public static void main(String[] args)throws Exception {
new Crawler().launchFrame();
}

}

转载于:https://www.cnblogs.com/sherlcok/archive/2011/05/27/2060282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值