我刚学Java不久,老师让做一个网页浏览器,只可以浏览源码那种,实现三种功能,我先贴代码
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.swing.JFileChooser;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import java.awt.FlowLayout;
import javax.swing.JTextPane;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.*;
import java.io.*;
import javax.swing.JScrollBar;
import java.awt.ScrollPane;
import java.awt.Panel;
import javax.swing.JSlider;
import java.awt.Scrollbar;
public class Text {
private JFrame frame;
private JTextField txtHttp;
private JTextArea textArea;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Text window = new Text();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Text() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame("网页浏览器");
frame.setBounds(100, 100, 705, 423);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
JMenuItem menuItem = new JMenuItem("\u5730\u5740\u680F");
menuBar.add(menuItem);
txtHttp = new JTextField();
txtHttp.setText("http://www.yahoo.com/");
menuBar.add(txtHttp);
txtHttp.setColumns(10);
JButton button = new JButton("\u8FDE\u63A5");
menuBar.add(button);
button.addActionListener(new MyMonitor());
JButton button_1 = new JButton("\u4FDD\u5B58");
menuBar.add(button_1);
button_1.addActionListener(new MyMonitor1());
JButton button_2 = new JButton("\u4FDD\u5B58\u56FE\u7247");
menuBar.add(button_2);