问题描述
// Java Program to Launch the browser
// and open a specific URI
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.net.*;
public class WOAH extends JFrame implements ActionListener{
//Creates a list of constants,these are the names
private enum Actions {
Open,Close
}
// frame
static JFrame f;
public static void main(String[] LOLZ){
desk d = new desk();
// create a frame
f = new JFrame("Nudes");
// create a panel
JPanel p = new JPanel();
// create a button
JButton b = new JButton("LUNCH");
JButton c = new JButton("CLOTHS");
//sets value for Command name
b.setActionCommand(Actions.Open.name());
c.setActionCommand(Actions.Close.name());
// add Action Listener
b.addActionListener(d);
c.addActionListener(d);
p.add(b);
p.add(c);
f.add(p);
f.setVisible(true);
f.setSize(200,200);
}
// if button is pressed
public void actionPerformed(ActionEvent e)
{
try {
if (e.getActionCommand() == Actions.Open.name()) {
// create a URI
URI u = new URI("www.geeksforgeeks.org");
Desktop d = Desktop.getDesktop();
d.browse(u);
}
else if (e.getActionCommand() == Actions.Close.name()) {
System.exit(0);
}
}
catch (Exception evt) {
}
}
}
我正在尝试运行这组代码中的两组代码,为简单起见,我删除了使用 JOptionPane 方法运行的行。
我的目标是生成一个 JAR 文件,但在这行代码中,我不确定不兼容是什么。它可能是保存到外部文件的枚举列表或 Action$ 列表吗?还是 ActionListener ?有人有什么建议吗?
代码在 JAR 配置之外运行良好
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)