我的应用程序的JToolbar按钮在点击.jar格式时完全没有响应,但在Netbeans IDE上完全响应,我真的不明白为什么我遇到这个问题,这里有一个图片说明JToolBarButtons那个没有回应申请:
此外,我认为存在问题的代码部分如下所示:
public class MainMenu extends JFrame implements ActionListener{
MyDesktopPane dp = new MyDesktopPane();
String TITLE = "The complete payroll system ";
JMenuBar menubar = new JMenuBar();
JPanel panel_Bottom = new JPanel();
JPanel panel_Top = new JPanel();
JButton btnOut = new JButton(new ImageIcon(getClass ().getResource("logout.png")));
Image img = new ImageIcon(getClass().getResource("/16.jpg")).getImage();
public MainMenu() {
super("PayRoll System");
panel_Top.setLayout(new BorderLayout());
panel_Top.setPreferredSize(new Dimension(10,150));
JToolBar tool=createJToolBar();tool.setBackground(new Color(36,121,183));
panel_Top.add(tool,BorderLayout.PAGE_START);
getContentPane().add(panel_Top,BorderLayout.PAGE_START);
getContentPane().add(dp,BorderLayout.CENTER);
btnOut.setBounds(600,230,75,35);
dp.add(btnOut);
{
btnOut.addActionListener(this);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
UnloadWindow();
}
});
}
}
public void actionPerformed(ActionEvent e){
Login log= new Login();
Object source = e.getSource();
if(source == btnOut){
log.setLogin();
dispose();
}
}
protected JToolBar createJToolBar()
{
JToolBar toolbar = new JToolBar("Toolbar");
toolbar.add(CreateJToolbarButton("Employee-Entry", "employee.png", "Emp_Entry",
JToolBarActionListener));
toolbar.addSeparator();
toolbar.add(CreateJToolbarButton("Employee Position Settings", "setting.png","Settings",
JToolBarActionListener));
toolbar.addSeparator();
toolbar.add(CreateJToolbarButton("DTR", "admin.png","DTR",
JToolBarActionListener));
toolbar.addSeparator();
toolbar.add(CreateJToolbarButton("User - Settings", "inf.png","User_Settings",
JToolBarActionListener));
toolbar.addSeparator();
toolbar.add(CreateJToolbarButton("Cash_Advance", "cash.png","Cash_Advance",
JToolBarActionListener));
toolbar.addSeparator();
toolbar.add(CreateJToolbarButton("Employee - Payoll", "rep.png","Reports_Payroll",
JToolBarActionListener));
toolbar.addSeparator();
toolbar.add(CreateJToolbarButton("Notepad", "SimpleTextEdit.png", "Notepad",
JToolBarActionListener));
toolbar.addSeparator();
toolbar.add(CreateJToolbarButton("Calculator", "Calculator2.png", "Calculator",
JToolBarActionListener));
toolbar.addSeparator();
return toolbar;
}
ActionListener JToolBarActionListener = new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
empSettings set= new empSettings();
empEntry inf= new empEntry();
UserSettings panel1 = new UserSettings();
notepad note= new notepad();
BasicCalc calc= new BasicCalc();
empDeduction frameDeduct= new empDeduction();
empCashAdvance cash= new empCashAdvance();
empPayroll pay = new empPayroll();
String source = e.getActionCommand();
if(source == "Emp_Entry")
{
inf.setEntry();
}
if (source == "Settings")
{
set.setSettings();
}
if (source == "Reports_Payroll")
{
pay.setPay();
}
if (source == "DTR")
{
frameDeduct.setDeduct();
}
if (source == "Notepad")
{
note.setNote();
}
if (source == "Calculator")
{
calc.setCalc();
}
if (source == "User_Settings")
{
panel1.frameUser();
}
if(source == "Cash_Advance")
{
cash.setCash();
}
}
};
protected void paintComponent(Graphics g) {
Graphics2D graphics = (Graphics2D) g.create();
Image img = new ImageIcon(getClass().getResource("/16.jpg")).getImage();
graphics.drawImage(img, 0, 0, getWidth(), getHeight(), null);
graphics.dispose();
}
protected void UnloadWindow()
{
try
{
int reply = JOptionPane.showConfirmDialog(this,"Are you sure to exit?",TITLE,JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE);
if (reply == JOptionPane.YES_OPTION)
{
setVisible(false);
System.exit(0);
}
else {
}
}
catch(Exception e)
{}
}
public JButton CreateJToolbarButton(String srcToolTipText,String srcImageLocation,String srcActionCommand, ActionListener JToolBarActionListener)
{
JButton bttnToolbar = new JButton(new ImageIcon(getClass ().getResource (srcImageLocation)));
bttnToolbar.setActionCommand(srcActionCommand);
bttnToolbar.setToolTipText(srcToolTipText);
bttnToolbar.setCursor(new Cursor(Cursor.HAND_CURSOR));
bttnToolbar.setFont(new Font("Dialog", Font.PLAIN, 12));
bttnToolbar.addActionListener(JToolBarActionListener);
return bttnToolbar;
}
public void setMain(){
MainMenu p1= new MainMenu();
p1.setSize(1228,700);
p1.setLocation(70,15);
p1.setVisible(true);
p1.setResizable(false);
}
public static void mainPane(){
new MainMenu ();
}
如果有人能帮助我,我将不胜感激,谢谢。
答案 0 :(得分:0)
我可以通过打开 regedit.exe ,然后导航到 HKEY_CLASSES_ROOT \ jarfile \ shell \ open \ command 并更改Javaw.exe路径来解决此问题。值:" C:\ Program Files \ Java \ jre7 \ bin \ javaw.exe" -jar"%1" % to:" C:\ Program Files(x86)\ Java \ jdk1.7.0_45 \ bin \ javaw.exe" -jar"%1" %强> 的
" C:\ Program Files(x86)\ Java \ jdk1.7.0_45 \ bin \ javaw.exe" 是我的IDE正在使用的Javaw.exe路径为了在没有任何问题的情况下执行应用程序,当应用程序在Netbeans IDE外部启动时,JToolbar按钮现在可以正常工作。