| | |
Trying to open explorer inside my java window
![]() |
Hi there.I have a quick question.I wrote this program to look like my own browser.It views the code of the url givven and it was suppose to be a browser too.The button explanations are as following:
CODE=Shows the code of the given url
VIEW=When you push it it was supposed to open the page in the window.(This is the part i need help in.)
Please help me.
Some other explanations ----> Pencere means window.
The code is given below:
CODE=Shows the code of the given url
VIEW=When you push it it was supposed to open the page in the window.(This is the part i need help in.)
Please help me.
Some other explanations ----> Pencere means window.
The code is given below:
Java Syntax (Toggle Plain Text)
import java.net.*; import java.io.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.border.*; import java.util.Date; import java.util.Calendar; class pencere extends JFrame{ JTextArea ta; JScrollPane sp; Container cont; Toolkit kit; Dimension dim; int sw,sh; ust pan; public pencere(){ setTitle("URL Viewer 1.0"); cont = this.getContentPane(); kit = this.getToolkit(); dim = kit.getScreenSize(); sw =dim.width;sh=dim.height; this.setSize(sw-100,sh-100); this.setLocation(50,50); ta=new JTextArea(); ta.setEditable(false); ta.setBackground(new Color(0xde,0xde,0xde)); ta.setTabSize(3); sp=new JScrollPane(ta); pan=new ust(this); cont.add(pan,BorderLayout.NORTH); cont.add(sp,BorderLayout.CENTER); } } class ust extends JPanel{ JTextField tf; JButton b1,b2,b3; pencere pen; Runtime r; Process p= null; Border bor; URL url1; URLConnection uconn; String ipstr; public ust(pencere vpen){ this.pen = vpen; this.setLayout(new FlowLayout()); tf=new JTextField(30); tf.setText("http://"); bor= BorderFactory.createEtchedBorder(); this.setBorder(bor); b1=new JButton("CODE"); b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ ust.this.code(); } }); r= Runtime.getRuntime(); b2=new JButton("VIEW"); b2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ String web[] ={"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE",tf.getText()}; try{ p = r.exec(web); } catch(Exception e){ JOptionPane.showMessageDialog(pen, "Invalid URL", "Warning", JOptionPane.WARNING_MESSAGE); } } }); b3=new JButton("Info"); b3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ ust.this.info(); } }); add(tf);add(b1);add(b2);add(b3); } public void code(){ try{ url1=new URL(tf.getText());; uconn =url1.openConnection(); pen.ta.setText(""); BufferedReader in=new BufferedReader(new InputStreamReader(url1.openStream())); String source; int i=0; while((source=in.readLine())!=null){ pen.ta.append(i++ +"\t| "); pen.ta.append(source+"\n"); } } catch(Exception e){ JOptionPane.showMessageDialog(pen, "Invalid URL", "Warning", JOptionPane.WARNING_MESSAGE); } } public void info(){ final JDialog infosu=new JDialog(new Frame(),"Bilgiler"); JLabel defprot=new JLabel("DefaultPort:"+url1.getDefaultPort()); JButton kap=new JButton("Kapat"); kap.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae){ infosu.setVisible(false); } }); JLabel file=new JLabel("File:"+url1.getFile()); JLabel host=new JLabel("Host:"+url1.getHost()); JLabel path=new JLabel("Path:"+url1.getPath()); JLabel protocol=new JLabel("Protocol:"+url1.getProtocol()); JLabel ref=new JLabel("Reference:"+url1.getRef()); JLabel all=new JLabel("All:"+url1.toString()); Date dat=new Date(uconn.getLastModified()); JLabel lm=new JLabel("LM:"+dat.toString()); Date exp=new Date(uconn.getExpiration()); JLabel expire=new JLabel("Expire:"+exp.toString()); try{ ipstr=InetAddress.getByName(url1.getHost()).getHostAddress(); }catch(Exception e){} JLabel ip=new JLabel("IP no:"+ipstr); infosu.getContentPane().setLayout(new GridLayout(11,1)); Container dcont=infosu.getContentPane(); dcont.add(kap); dcont.add(defprot); dcont.add(file); dcont.add(host); dcont.add(path); dcont.add(protocol); dcont.add(ref); dcont.add(all); dcont.add(lm); dcont.add(expire); dcont.add(ip); infosu.setSize(250,200); infosu.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); infosu.setVisible(true); } } public class URLviewer { public static void main(String args[]){ JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); pencere pen=new pencere(); pen.setVisible(true); pen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
"By the data to date, there is only one animal in the Galaxy dangerous to man—man himself. So he must supply his own indispensable competition. He has no enemy to help him."
From Time Enough for Love by Robert A. Heinlein
From Time Enough for Love by Robert A. Heinlein
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
You are using a JTextArea so going to a webpage via that JComponent is out the window so switch your JTextArea to a JTextPane. In the JTextPane api the have a setURL method. Use that method to go to a particular webpage
Finally i have become a guru. I have attained java nirvana
Richard West
You are using a JTextArea so going to a webpage via that JComponent is out the window so switch your JTextArea to a JTextPane. In the JTextPane api the have a setURL method. Use that method to go to a particular webpage
Finally i have become a guru. I have attained java nirvana
Richard West
Microsoft uses "One World, One Web, One Program" as a slogan.
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
Doesn’t that sound like "Ein Volk, Ein Reich, Ein Führer" to you, too?
— Eric S. Raymond
Tell me what type of software do you like and what would you pay for it
http://www.daniweb.com/techtalkforums/thread19660.html
![]() |
Similar Threads
- XP Error: Internet Explorer link won't open (Windows NT / 2000 / XP)
- can`t open more than one window of internet explorer (Web Browsers)
- windows explorer won't open. (Viruses, Spyware and other Nasties)
- Can't Erase Giant Inbox: Can't open multiple Explorer windows (Windows 95 / 98 / Me)
- Internet explorer new windows dont open (Web Browsers)
- What Language is used in software like Adobe Photoshop? (C++)
Other Threads in the Java Forum
- Previous Thread: A question on an error in a SpringLayout example program
- Next Thread: about Yahoo search engine
| Thread Tools | Search this Thread |
-xlint actionlistener add android applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse equation error event fractal ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper idea image int j2me j2seprojects java javac javaee javame javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main method mobile myregfun netbeans notdisplaying number online pearl printf problem program qt researchinmotion rotatetext rsa scanner screen scrollbar server set singleton sms sort spamblocker sql string superclass swing system textfields thread threads time title tree tutorial-sample update variablebinding windows xor





