gpt4 book ai didi

java - 为什么此代码在 Vista 中有效,但在 7 中无效?

转载 作者:行者123 更新时间:2023-12-01 05:44:31 24 4
gpt4 key购买 nike

出于某种原因,每次我让别人在 Vista 中运行这个程序时,它都能完美地工作,但是一旦我将它转移到 Windows 7 PC 上,它就会停止在 ActionListener 的操作执行方法的中间,这意味着我可以单击我的选择,但是它永远不会说选择的尺寸。有什么办法可以解决这个问题吗?

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 的计算机。执行后,代码无法继续执行,即它从未打印出“选择的大小”字样。该程序的其余部分从 C:\Users\?\AppData\TimeLineMacroProgram 文件夹中引入一个 csv 文件,然后在同一目录中创建一个图像。但这是当前已损坏的代码部分。每当 GUI 弹出时,我都会选择 9"选项并单击完成,这应该将 9 作为参数传递,然后打印出“Size Selected”,但它不仅会处理窗口。请帮忙。

最佳答案

远景猜测:

如果宽度和高度文本字段没有内容,则操作监听器会退出:在两个 NumberFormatException 后返回。这将阻止显示“已选择的尺寸”,并且不会处理该框架。如果您得到输出“成功获得屏幕分辨率”,然后它似乎停止工作,这可能就是原因。但如果您遇到这种情况,然后单击其他内容,然后单击“完成”,它将打印选定的尺寸。

关于java - 为什么此代码在 Vista 中有效,但在 7 中无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6254966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com