Java Swing AWT Program to Generate Source Code of Given Website URL inside TextArea Widget GUI Desktop App

You are currently viewing Java Swing AWT Program to Generate Source Code of Given Website URL inside TextArea Widget GUI Desktop App

Are you looking to learn the topic of “Java Swing AWT Program to Generate Source Code of Given Website URL inside TextArea Widget GUI Desktop App”? If yes then you are in the perfect article. Let’s do this task below.

Java Swing AWT Program to Generate Source Code of Given Website URL inside TextArea Widget GUI Desktop App

sourcecode.java

import java.awt.*;  
import java.awt.event.*;  
import java.io.InputStream;  
import java.net.*;  
public class SourceGetter extends Frame implements ActionListener{  
    TextField tf;  
    TextArea ta;  
    Button b;  
    Label l;  
    SourceGetter(){  
        super("Source Getter Tool - Javatpoint");  
        l=new Label("Enter URL:");  
        l.setBounds(50,50,50,20);  
          
        tf=new TextField();  
        tf.setBounds(120,50,250,20);  
          
        b=new Button("Get Source Code");  
        b.setBounds(120, 100,120,30);  
        b.addActionListener(this);  
          
        ta=new TextArea();  
        ta.setBounds(120,150,250,150);  
          
        add(l);add(tf);add(b);add(ta);  
        setSize(400,400);  
        setLayout(null);  
        setVisible(true);  
    }  
    public void actionPerformed(ActionEvent e){  
        String s=tf.getText();  
        if(s==null){}  
        else{  
            try{  
            URL u=new URL(s);  
            URLConnection uc=u.openConnection();  
          
            InputStream is=uc.getInputStream();  
            int i;  
            StringBuilder sb=new StringBuilder();  
            while((i=is.read())!=-1){  
                sb.append((char)i);  
            }  
            String source=sb.toString();  
            ta.setText(source);  
            }catch(Exception ex){System.out.println(e);}  
        }  
    }  
    public static void main(String[] args) {  
        new SourceGetter();  
    }  
}

Final Thoughts

I hope this article “Java Swing AWT Program to Generate Source Code of Given Website URL inside TextArea Widget GUI Desktop App” will be useful to you. If you face any issues please let me know via the comment section. Share this article with other Java program developers via social networks. Thank You!

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply