944,017 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 5338
  • Java RSS
Aug 31st, 2005
0

Trying to open explorer inside my java window

Expand Post »
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:


Java Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster
johnroach1985 is offline Offline
135 posts
since Apr 2004
Aug 31st, 2005
0

Re: Trying to open explorer inside my java window

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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004
Aug 31st, 2005
0

Re: Trying to open explorer inside my java window

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
Reputation Points: 11
Solved Threads: 0
Junior Poster
johnroach1985 is offline Offline
135 posts
since Apr 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: A question on an error in a SpringLayout example program
Next Thread in Java Forum Timeline: about Yahoo search engine





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC