-2

I am an absolute beginner in coding. I would like to know why is my Jframe blank when run, how do I fix it. From what I have research on the internet it seems that I should put the component inside the JFrame as it is empty but how do I do it

My Code

public class Video extends JFrame
{

public static void main(String[] args) throws URISyntaxException {

final URI uri = new URI("https://www.youtube.com/watch?v=rl0YiZjTqpw");

class OpenUrlAction implements ActionListener 
{
  @Override public void actionPerformed(ActionEvent e) {
    open(uri);
  }
}

JFrame frame = new JFrame("Links");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(410, 400);
Container container = frame.getContentPane();
container.setLayout(new GridBagLayout());
JButton btnclickHereTo = new JButton();
btnclickHereTo.setText("<HTML> <FONT color=\"#000099\"><U>Click Here To Watch Video</U></FONT>");
btnclickHereTo.setHorizontalAlignment(SwingConstants.LEFT);
btnclickHereTo.setBorderPainted(false);
btnclickHereTo.setOpaque(false);
btnclickHereTo.setBackground(Color.WHITE);
btnclickHereTo.setToolTipText(uri.toString());
btnclickHereTo.addActionListener(new OpenUrlAction());
container.add(btnclickHereTo);
frame.setVisible(true);
}
private static void open(URI uri) 
{
    if (Desktop.isDesktopSupported()) 
    {
      try 
      {
        Desktop.getDesktop().browse(uri);
      }
      catch (IOException e) 
      { /* TODO: error handling */ }
    }
    else
    { /* TODO: error handling */ }
  }

}
Daren Lua
  • 1
  • 2
  • From the flagging options - "_Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the **shortest code necessary to reproduce it in the question itself**. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example._" – takendarkk Aug 01 '17 at 15:04
  • btw: your code should be a copy-pastable text and not a screenshot – ΦXocę 웃 Пepeúpa ツ Aug 01 '17 at 15:08
  • You could take a look at https://stackoverflow.com/questions/7201722, which seems to be related to your question. – Freek de Bruijn Aug 01 '17 at 21:33

1 Answers1

1
public void setVisible(boolean b) {

Why would you override the setVisible(...) method of your frame? There is no reason to do that.

I am an absolute beginner in coding

Start with something basic, like the example from the Swing tutorial on How to Make Frames.

Keep a reference to the tutorial link handy since it contains information and examples for all Swing basics.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • I have delete that part so what can i do to make it show – Daren Lua Aug 01 '17 at 16:00
  • @DarenLua, read the tutorial for a working example. There is also example code for using the "Desktop" API. You need to spend time reading to learn Swing. – camickr Aug 01 '17 at 17:00