带有静态网址的java浏览器

时间:2015-10-11 09:10:23

标签: java browser

我可以通过输入网址来完成这项工作。但我需要的是一个字符串变量来链接网址和自动加载这个页面。并通过输入密码弹出并退出按钮退出。

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;

public class main extends JFrame{

    private JTextField addressBar;
    private JEditorPane display;
    private String link = "http://www.google.lk";

    public main(){

        addressBar= new JTextField(link);
        addressBar.addActionListener(
                new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        // TODO Auto-generated method stub
                        loadCrap(e.getActionCommand());
                    }
                }
                );
        add(addressBar,BorderLayout.NORTH);
        display = new JEditorPane();
        display.setEditable(false);
        display.addHyperlinkListener(
                new HyperlinkListener() {

                    @Override
                    public void hyperlinkUpdate(HyperlinkEvent e) {
                        // TODO Auto-generated method stub
                        //if(e.getEventType()==HyperlinkEvent.EventType.ACTIVATED){
                            loadCrap(e.getURL().toString());
                        //}

                    }
                }
                );
        add(new JScrollPane(display), BorderLayout.CENTER);


    }

    private void loadCrap(String usertext){
        try{
            display.setPage(usertext);
            addressBar.setText(usertext);
        }catch (Exception e){
            System.out.println("Shit!");
        }

    }
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        JFrame browser = new main();
        browser.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        browser.setExtendedState(JFrame.MAXIMIZED_BOTH);

        browser.setUndecorated(true);

        browser.setVisible(true);
    }

}

1 个答案:

答案 0 :(得分:0)

您可以尝试使用if ($_POST['login']) { $query= "SELECT * FROM users WHERE email='".mysqli_real_escape_string($link, $_POST['loginemail'])."' AND password='".md5(md5($_POST['loginemail'])+$_POST['loginpassword'])."' LIMIT 1"; $result= mysqli_query($link, $query); if ($result->num_rows==1) { $row= mysqli_fetch_array($result); $_SESSION['id']= $row['id']; header("location:mainpage.php"); exit(0);//Best practice to quit the execution after done the page redirection. } else { $error= "We could not find any user with the submitted informations!"; } }

这会将页面加载到括号内的网址。

以下是一个例子:

.setPage

以下是完整代码:http://pastebin.com/ki4bs4kC