| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 652 人关注过本帖
标题:请教
只看楼主 加入收藏
THE
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-6-30
收藏
 问题点数:0 回复次数:2 
请教
import java.awt.BorderLayout;
import java.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import

import javax.swing.JButton;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSeparator;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.JToolBar;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import com.swtdesigner.SwingResourceManager;


public class Liulanqi extends JFrame {

    private JTextField textFieldURL;
    private JMenuBar menuBar;
    /**
     * Launch the application
     * @param args
     */
    public static void main(String args[]) {
        try {
            Liulanqi frame = new Liulanqi();
            frame.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the frame
     */
    public Liulanqi() {
        super();
        setTitle("Show");

        setName("go");
        setBounds(100, 100, 611, 408);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        final JToolBar toolBar = new JToolBar();
        getContentPane().add(toolBar, BorderLayout.NORTH);

        final JButton button_1 = new JButton();
        button_1.setName("backButton");
        button_1.setIcon(SwingResourceManager.getIcon(Liulanqi.class, "back16.gif"));
        toolBar.add(button_1);

        final JButton button = new JButton();
        button.setName("forwardButton");
        button.setIcon(SwingResourceManager.getIcon(Liulanqi.class, "forward16.gif"));
        toolBar.add(button);

        final JButton button_2 = new JButton();
        button_2.setName("shiftButton");
        button_2.setIcon(SwingResourceManager.getIcon(Liulanqi.class, "refresh16.gif"));
        toolBar.add(button_2);

        final JLabel locationLabel = new JLabel();
        locationLabel.setText("Location:");
        toolBar.add(locationLabel);

        textFieldURL = new JTextField();
        toolBar.add(textFieldURL);

        final JButton goButton = new JButton();

        goButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                gobutton_actionPerformed(arg0);
            }
        });
        
        
        goButton.setText("Go");
        toolBar.add(goButton);

        final JButton button_4 = new JButton();
        button_4.setIcon(SwingResourceManager.getIcon(Liulanqi.class, "s.gif"));
        toolBar.add(button_4);

        menuBar = new JMenuBar();
        setJMenuBar(menuBar);

        final JMenu menu = new JMenu();
        menu.setText("文件");
        menuBar.add(menu);

        final JMenuItem menuItem = new JMenuItem();
        menuItem.setText("退出");
        menu.add(menuItem);

        final JMenu menu_1 = new JMenu();
        menu_1.setText("标签");
        menuBar.add(menu_1);

        final JMenuItem menuItem_1 = new JMenuItem();
        menuItem_1.setText("添加到收藏夹");
        menu_1.add(menuItem_1);

        final JMenuItem menuItem_2 = new JMenuItem();
        menuItem_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                
            }
        });
        menuItem_2.setText("删除收藏夹");
        menu_1.add(menuItem_2);

        final JMenu menu_2 = new JMenu();
        menu_2.setText("帮助");
        menuBar.add(menu_2);

        JEditorPane jEditorPane = new JEditorPane();
        jEditorPane.setEditable(false); // 设置不可编辑
        getContentPane().add(jEditorPane, BorderLayout.CENTER);
        //
    }

    private static void addPopup(Component component, final JPopupMenu popup) {
        component.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                if (e.isPopupTrigger())
                    showMenu(e);
            }
            public void mouseReleased(MouseEvent e) {
                if (e.isPopupTrigger())
                    showMenu(e);
            }
            private void showMenu(MouseEvent e) {
                popup.show(e.getComponent(), e.getX(), e.getY());
            }
        });
    }
    void gobutton_actionPerformed(ActionEvent e) { // 输入地址后响应button "Go"
        try {
            jEditorPane.setPage(textFieldURL.getText()); // 显示URL     
                          //错误,无法解析jEditorPane
        } catch (IOException ex) {
            JOptionPane msg = new JOptionPane();
            JOptionPane.showMessageDialog(this, "URL地址不正确:"
                    + textFieldURL.getText(), "输入不正确!", 0);
        }
    }
}
为什么在方法gobutton_actionPerformed(ActionEvent e)中无法解析jEditorPane?
谢谢!
2008-04-22 22:52
贝贝ai宝宝
Rank: 1
来 自:北京
等 级:新手上路
帖 子:15
专家分:0
注 册:2008-4-22
收藏
得分:0 
o(∩_∩)o...
把JEditorPane jEditorPane;声明在方法外面,
把JEditorPane jEditorPane = new JEditorPane();
改成jEditorPane = new JEditorPane(),否则为二次定义。

贝贝
2008-04-23 18:44
THE
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-6-30
收藏
得分:0 
谢谢!
2008-04-30 16:55
快速回复:请教
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.033394 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved