0

Ok hello, What I want is when my button is pressed I want read the text from a URL and display it in the GUI,

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
   //??????????????????? 
}   

I am very confused on this. I saw it in a Open Source project and I can't get it to work :/ All I really want is it to open up to a raw github file (in the GUI) to display the contents of the github.

This is the github link

I want the text to display as if it where actually in the application.

Thanks for any help

Nick Rippe
  • 6,465
  • 14
  • 30
Fusion
  • 70
  • 1
  • 10
  • 1
    What do you mean by "open up to a raw github...'? This is very confusing to me. Please tell the specifics. – Hovercraft Full Of Eels Feb 23 '14 at 04:02
  • you mean pop up a web view so that a particular github page is displayed on your device? – Marc B Feb 23 '14 at 04:03
  • Like it display the text like I just made the text in the GUI. – Fusion Feb 23 '14 at 04:03
  • Display the text ***how***? In a JTextArea? A JTextField? A JLabel? Please tell the specifics as they are important. – Hovercraft Full Of Eels Feb 23 '14 at 04:04
  • `"I think a text area."` -- I think you're confused. If you want to open a file an display it's contents, then do so. But a GIThup concept is something entirely different. Perhaps you want to re-think your question and try to clarify it from the ground up. – Hovercraft Full Of Eels Feb 23 '14 at 04:12
  • Something like this final URL url = new URL("https://raw.github.com/Fusionn/version/master/version.txt"); final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); But this wont work – Fusion Feb 23 '14 at 04:33

1 Answers1

0

What I would do, is go ahead and make a new JFrame, named something different than your previous one, but set it's visibility to false. Within that new JFrame, "ex", add a layout and then add you github info into the layout. ex:

JFrame ex = new JFrame();
ex.setSize(50,50);
ex.setVisible(false);
ex.setResizable(falsE);
ex.setDefaultCloseOperation(JFrame.Dispose);
//Use "dispose" to exit the window but not terminate your program

and then, when you have a JButton clicked, or whatever you're using, use an actionevent. ex:

jButton1.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        System.out.println("JButton1 Button pressed");
        ex.setVisible(true);

    }

});
  • 4
    *"go ahead and make a new JFrame"* Or alternately *not* use another `JFrame`. See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Feb 23 '14 at 04:18