由於某種原因,每次有人在Vista中運行該程序時,它都可以完美運行,但只要將它移到Windows 7 PC上,它就會停止在ActionListener的Action Performed Method中,這意味着我可以點擊我的選擇,但它永遠不會說大小選擇。 有什麼辦法解決這個問題嗎?爲什麼這個代碼在Vista中工作,但不是7?
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class SizerFrame extends JFrame {
ButtonGroup buttons = new ButtonGroup();
JTextField width = new JTextField(2);
JTextField height = new JTextField(2);
double inchesPerTimeline = 2.1;
public SizerFrame()
{
super("Timeline Application");
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(screen.width/2-125,screen.height/2-90,250,180);
getContentPane().setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
int[] gridX = new int[]{0,0,0,0};
int[] gridY = new int[]{0,1,2,3};
int[] gridW = new int[]{1,1,2,5};
String[] titles = new String[]{"6\"","9\"","10\"","Custom"};
String[] actions = new String[]{"6","9","10","C"};
for (int a = 0; a < 4; a++)
{
JRadioButton current = new JRadioButton(titles[a]);
current.setActionCommand(actions[a]);
c.gridx = gridX[a];
c.gridy = gridY[a];
c.gridwidth = gridW[a];
buttons.add(current);
getContentPane().add(current,c);
}
c.gridwidth = 1;
String[] title = new String[]{" ","Width","Height"};
gridX = new int[]{9,10,12};
for (int a = 0; a< 3; a++)
{
c.gridx = gridX[a];
getContentPane().add(new JLabel(title[a]),c);
}
c.gridx = 11;
getContentPane().add(width,c);
c.gridx = 13;
getContentPane().add(height,c);
c.gridx = 11;
c.gridy = 0;
c.gridwidth = 2;
JButton button = new JButton("Done");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ButtonModel x = buttons.getSelection();
String size = "XXX";
System.out.println("Getting screen resolution");
int screenRes = Toolkit.getDefaultToolkit().getScreenResolution();
System.out.println("Successfully got screen resolution");
if (x!=null)
size = x.getActionCommand();
try{
TimeTable.width = new Integer(size)*screenRes;
TimeTable.height = (int)((TimeTable.titleCount+1)*inchesPerTimeline*screenRes);
}
catch(NumberFormatException ex)
{
try{
TimeTable.width = (int)(new Double(width.getText().trim())*screenRes);
TimeTable.height = (int)(new Double(height.getText().trim())*screenRes);
}
catch (NumberFormatException except)
{
return;
}
}
TimeTable.ready = true;
System.out.println("Size selected");
dispose();
}
});
getContentPane().add(button,c);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent winEvt){
System.exit(0);
}
});
setVisible(true);
}
}
簡要說明: 我有一個在Windows Vista用完的Excel宏,我試圖將其分發到運行Windows 7在執行的計算機代碼沒有永遠繼續也就是說,它在這之後執行打印出「Size selected」字樣。程序的其餘部分從C:\ Users \?\ AppData \ TimeLineMacroProgram文件夾中導入一個csv文件,稍後在同一目錄中創建一個映像。但是這是目前破解的代碼的一部分。每當GUI彈出時,我選擇9「的選項,並單擊完成,應該通過9作爲參數,然後打印出」大小選擇「,但它不是它只處理窗口。請幫助。
我只能懷疑JDK中存在一個錯誤 - 您是否在兩個版本中使用完全相同的JDK版本? – Liv 2011-06-06 16:21:22
不考慮它作爲一個程序導出到其他使用類文件的計算機,唯一類似的問題將是JRE – 2011-06-06 16:22:38
程序是否掛起,終止或錯誤? – Shaded 2011-06-06 16:23:47