我正在编写一个简单的 JFrame/Application,它会打开一个带有一些简单按钮的小程序。我只想让这些按钮在点击时打开某些网页/链接。
代码:
package me.jamplifier;
import java.awt.Desktop;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import javax.swing.*;
public class Launcher extends JFrame
{
public Launcher()
{
JFrame frame = new JFrame("Hurricane Craft");
frame.setVisible(true);
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Welcome to Hurricane Craft");
JPanel panel = new JPanel();
frame.add(panel);
panel.add(label);
JButton site = new JButton("Site");
JButton forums = new JButton("Forums");
panel.add(site);
panel.add(forums);
}
public static void main(String[] args)
{
new Launcher();
}
}