Trying to open explorer inside my java window

Reply

Join Date: Apr 2004
Posts: 127
Reputation: johnroach1985 is an unknown quantity at this point 
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Trying to open explorer inside my java window

 
0
  #1
Aug 31st, 2005
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:


  1. import java.net.*;
  2. import java.io.*;
  3. import java.awt.*;
  4. import javax.swing.*;
  5. import java.awt.event.*;
  6. import javax.swing.border.*;
  7. import java.util.Date;
  8. import java.util.Calendar;
  9.  
  10. class pencere extends JFrame{
  11. JTextArea ta;
  12. JScrollPane sp;
  13. Container cont;
  14. Toolkit kit;
  15. Dimension dim;
  16. int sw,sh;
  17. ust pan;
  18.  
  19. public pencere(){
  20. setTitle("URL Viewer 1.0");
  21. cont = this.getContentPane();
  22. kit = this.getToolkit();
  23. dim = kit.getScreenSize();
  24. sw =dim.width;sh=dim.height;
  25. this.setSize(sw-100,sh-100);
  26. this.setLocation(50,50);
  27. ta=new JTextArea();
  28. ta.setEditable(false);
  29. ta.setBackground(new Color(0xde,0xde,0xde));
  30. ta.setTabSize(3);
  31. sp=new JScrollPane(ta);
  32. pan=new ust(this);
  33.  
  34. cont.add(pan,BorderLayout.NORTH);
  35. cont.add(sp,BorderLayout.CENTER);
  36.  
  37. }
  38. }
  39. class ust extends JPanel{
  40. JTextField tf;
  41. JButton b1,b2,b3;
  42. pencere pen;
  43. Runtime r;
  44. Process p= null;
  45. Border bor;
  46. URL url1;
  47. URLConnection uconn;
  48. String ipstr;
  49.  
  50. public ust(pencere vpen){
  51. this.pen = vpen;
  52. this.setLayout(new FlowLayout());
  53. tf=new JTextField(30);
  54. tf.setText("http://");
  55. bor= BorderFactory.createEtchedBorder();
  56. this.setBorder(bor);
  57. b1=new JButton("CODE");
  58. b1.addActionListener(new ActionListener(){
  59. public void actionPerformed(ActionEvent ae){
  60. ust.this.code();
  61. }
  62. });
  63. r= Runtime.getRuntime();
  64.  
  65. b2=new JButton("VIEW");
  66. b2.addActionListener(new ActionListener(){
  67. public void actionPerformed(ActionEvent ae){
  68. String web[] ={"C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE",tf.getText()};
  69. try{
  70.  
  71. p = r.exec(web);
  72. }
  73. catch(Exception e){
  74. JOptionPane.showMessageDialog(pen,
  75. "Invalid URL",
  76. "Warning",
  77. JOptionPane.WARNING_MESSAGE);
  78. }
  79. }
  80. });
  81.  
  82. b3=new JButton("Info");
  83. b3.addActionListener(new ActionListener(){
  84. public void actionPerformed(ActionEvent ae){
  85. ust.this.info();
  86. }
  87. });
  88.  
  89. add(tf);add(b1);add(b2);add(b3);
  90.  
  91. }
  92.  
  93. public void code(){
  94. try{
  95. url1=new URL(tf.getText());;
  96. uconn =url1.openConnection();
  97. pen.ta.setText("");
  98. BufferedReader in=new BufferedReader(new InputStreamReader(url1.openStream()));
  99. String source;
  100. int i=0;
  101. while((source=in.readLine())!=null){
  102. pen.ta.append(i++ +"\t| ");
  103. pen.ta.append(source+"\n");
  104. }
  105. }
  106. catch(Exception e){
  107. JOptionPane.showMessageDialog(pen,
  108. "Invalid URL",
  109. "Warning",
  110. JOptionPane.WARNING_MESSAGE);
  111. }
  112. }
  113. public void info(){
  114. final JDialog infosu=new JDialog(new Frame(),"Bilgiler");
  115. JLabel defprot=new JLabel("DefaultPort:"+url1.getDefaultPort());
  116. JButton kap=new JButton("Kapat");
  117. kap.addActionListener(new ActionListener(){
  118. public void actionPerformed(ActionEvent ae){
  119. infosu.setVisible(false);
  120. }
  121. });
  122. JLabel file=new JLabel("File:"+url1.getFile());
  123. JLabel host=new JLabel("Host:"+url1.getHost());
  124. JLabel path=new JLabel("Path:"+url1.getPath());
  125. JLabel protocol=new JLabel("Protocol:"+url1.getProtocol());
  126. JLabel ref=new JLabel("Reference:"+url1.getRef());
  127. JLabel all=new JLabel("All:"+url1.toString());
  128. Date dat=new Date(uconn.getLastModified());
  129. JLabel lm=new JLabel("LM:"+dat.toString());
  130. Date exp=new Date(uconn.getExpiration());
  131. JLabel expire=new JLabel("Expire:"+exp.toString());
  132. try{
  133. ipstr=InetAddress.getByName(url1.getHost()).getHostAddress();
  134. }catch(Exception e){}
  135. JLabel ip=new JLabel("IP no:"+ipstr);
  136.  
  137.  
  138. infosu.getContentPane().setLayout(new GridLayout(11,1));
  139. Container dcont=infosu.getContentPane();
  140. dcont.add(kap);
  141. dcont.add(defprot);
  142. dcont.add(file);
  143. dcont.add(host);
  144. dcont.add(path);
  145. dcont.add(protocol);
  146. dcont.add(ref);
  147. dcont.add(all);
  148. dcont.add(lm);
  149. dcont.add(expire);
  150. dcont.add(ip);
  151. infosu.setSize(250,200);
  152. infosu.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
  153. infosu.setVisible(true);
  154. }
  155.  
  156.  
  157. }
  158.  
  159.  
  160.  
  161.  
  162.  
  163. public class URLviewer {
  164.  
  165. public static void main(String args[]){
  166. JFrame.setDefaultLookAndFeelDecorated(true);
  167. JDialog.setDefaultLookAndFeelDecorated(true);
  168. pencere pen=new pencere();
  169. pen.setVisible(true);
  170. pen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  171.  
  172. }
  173. }
"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
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 7
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Trying to open explorer inside my java window

 
0
  #2
Aug 31st, 2005
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
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
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 127
Reputation: johnroach1985 is an unknown quantity at this point 
Solved Threads: 0
johnroach1985's Avatar
johnroach1985 johnroach1985 is offline Offline
Junior Poster

Re: Trying to open explorer inside my java window

 
0
  #3
Aug 31st, 2005
firstly i wanna say "long live gurus" .secondly can you please change the code and post it cause i couldn't change the darn thing kept giving me errors
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC