- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
使用 JDK 9,我的 swing 应用程序在具有 4k highdpi 和正常 1080p 正常 dpi。标签、组合框等看起来都不错,而且在 4k 屏幕上放大。但是我的 JPanel 也是如此,我在其中绘制自定义图像。我可以禁用吗这个 JPanel 的缩放比例来处理我自己的绘图?我在用apache-commons bicubic interpolation 绘制更多细节更高未缩放的分辨率,但由于开箱即用,我只能绘制“正常”尺寸。
亲切的问候
最佳答案
(编辑:以使用大约 2 年后产生的形式从我的库中粘贴新版本。评论可能不是最新的,但现在更适合生产代码。)
Java 9 中的缩放似乎是这样工作的:您的 paint(Component)() 方法接收一个 Graphics2D 对象已经缩放。此外,组件大小(例如 myJFrame.setSize() , myJPanel.getWidth()) 被缩放对程序不可见,这意味着当您在 200% 的桌面上使用 setSize(800,600) 时,组件将为 1600x1200,但 getWidth/getHeight 将返回 800/600 .
Can i disable the scaling for this one JPanel to handle drawing myself?
要将您的 Graphics 对象“重置”为缩放比例 1,请执行以下操作:
final Graphics2D g = (Graphics2D) graphics;
final AffineTransform t = g.getTransform();
final double scaling = t.getScaleX(); // Assuming square pixels :P
t.setToScale(1, 1);
g.setTransform(t);
要获得正确的尺寸,例如在绘制之前用黑色填充整个背景:
final int w = (int) Math.round(getWidth() * scaling);
如果你这样做,你应该在 Java 9 和 Java 8 上得到想要的结果。
我刚刚为 Java 开发人员创建了一个类,他们力求更自定义的组件设计和/或原始绘图,其中系统的显示缩放比例应该是已知的,并且通常需要手动缩放。它应该可以解决 Java 8 和 Java 9 上的所有缩放问题。它是:
import javax.swing.*;
import java.awt.*;
import java.awt.geom.AffineTransform;
// Please note: This class emerged over time. It gets the job done, but it's horrible. Even the commenting is horrible.
/**
* TL;DR:
* <p>
* Call GUIScaling.initialize() at application start on the Swing thread.
* <p>
* If you set your own Component font sizes or border sizes or window sizes, multiply them by GUIScaling.GUISCALINGFACTOR_COMPONENTSANDFONTS and/or use the
* helper methods newDimension() and scaleForComponent(). Works on Java 8 and 9.
* <p>
* If you do your own custom graphics and want to have control down to the actual pixel, create an instance of GUIScalingCustomGraphics to obtain your
* Graphics2D at scaling 1 and your component's true physical width and height (Which Java 9 reports differently!), and scale all your graphics using
* GUIScaling.GUISCALINGFACTOR_CUSTOMGRAPHICS and/or use the helper method scaleForCustom(). The helper method scaleForRealComponentSize() can transform your
* mouse coordinates to the real physical coordinate, which Java 9 reports differently!
* <p>
* <p>
* <p>
* <p>
* <p>
* <p>
* <p>
* <p>
* <p>
* <p>
* GUIScaling class v[4, 2022-01-15 07!00 UTC] by dreamspace-president.com
* <p>
* This Swing class detects the system's display scaling setting, which is important to make your GUI and custom graphics scale properly like the user wants it.
* On a 4K display, for example, you'd probably set 200% in your system.
* <p>
* Not tested with Java less than 8!
* <p>
* On Java 8 (and with most but not all (e.g. no the default) LooksAndFeels), component sizes (e.g. JButton) and their font sizes will scale automatically, but
* if you have a certain border width in mind, or decided for a certain min and default window size or a certain font size, you have to upscale those on a
* non-100%-system. With this class, just multiply the values with GUISCALINGFACTOR_COMPONENTSANDFONTS. Done. newDimension() and scaleForComponent() help with
* that.
* <p>
* On Java 9, component sizes and their font sizes DO NOT SCALE from the perspective of the application, but in reality they are scaled: A window set to 800x600
* size will really be 1600x1200, but it will still report half this size when asked. A border of 50 pixels will really be 100 pixels. A Graphics2D object
* (paint method etc.) will have a scaling of 2! (Not if you just create a BufferedImage object and do createGraphics(), the scale here will be 1.) So, you
* don't have to bother with GUI scaling here at all. YOU CAN STILL USE GUISCALINGFACTOR_COMPONENTSANDFONTS, because this class will set it to 1 on Java 9. This
* is detected by indeed checking the scaling of a Graphics2D object. So, your Java 8 and 9 component/font code will be exactly the same in regards to scaling.
* <p>
* CUSTOM GRAPHICS: If you do your own painting and want to insist on true physical pixels (in which case obviously you'd have to scale your fonts with
* GUISCALINGFACTOR_CUSTOMGRAPHICS instead of GUISCALINGFACTOR_COMPONENTSANDFONTS), on Java 9 you have to reset the scaling of the Graphics2D object the
* paint(Component)() method gives you from 2 to 1, and (also Java 9) you have to adjust the width/height reported by your component. Both is done by making an
* instance of GUIScalingCustomGraphics. You can do this blindly on Java 8 and 9, your code will stay the same. And then, apply this class'
* GUISCALINGFACTOR_CUSTOMGRAPHICS to scale everything according to system settings. Or, instead of insisting on true physical pixels, you could trust Java 9
* and not mess with the initial scaling - but then you'd have to distinguish whether you're dealing with Java 8 or 9, because on 8, you'd still have to scale
* your custom graphics. In case you decide for this, use GUISCALINGFACTOR_COMPONENTSANDFONTS for your custom graphics instead of
* GUISCALINGFACTOR_CUSTOMGRAPHICS because the former will be ***1*** on Java 9 but will be proper (e.g. 2.0 for a 200% system) on Java 8.
* <p>
* A weird problem that comes with Java 9: If you use the mouse coordinates as reported by the system (instead of, say, quasi-fix the physical mouse pointer
* invisibly at the screen center and make your own pointer based on coordinate differences), you will have HALF THE USUAL RESOLUTION. On Java 8, a 3840x2160
* screen will give you according mouse coordinates, but on Java 9, you get half these coordinates (if the system is set to scaling 200%). While
* scaleForRealComponentSize() helps correct this, a custom drawn mouse pointer will now step in 2 pixel distances, it can not reach every individual pixel any
* longer. I wish they had updated the MouseEvent class accordingly with additional float methods.
*/
final public class GUIScaling { // INITIAL TOUCHING of this class MUST be on Swing thread!
/**
* Call this at the start of your application ON THE SWING THREAD. This initializes the class and hence its values.
*/
public static void initialize() {
System.err.print("");
}
public static void setLookAndFeelDefault() {
// The last three (Nimbus etc.) DO NOT automatically scale their font sizes with the system's GUI scaling,
// so using the font size in those cases to derive the scaling WILL FAIL.
// Btw., the JButton font size at 100% Windows 10 system scaling is 11.0 in all cases but the last three.
GUIScaling.setLookAndFeel("Windows",
UIManager.getSystemLookAndFeelClassName(),
UIManager.getCrossPlatformLookAndFeelClassName(),
"Windows Classic",
"Nimbus",
"Metal",
"CDE/Motif");
}
/**
* By calling this, you ALSO initialize the class, so you don't HAVE TO use initialize() in that case (but it really doesn't matter). And you can indeed set
* a LookAndFeel of your choice, even though initialization of this class also sets AND TEMPORARILY USES a LookAndFeel.
*
* @param intendedLAFIs ANYTHING, but ideally a LookAndFeel name or several. The first value that equalsIgnoreCase an installed LookAndFeelInfo.getName()
* will be used.
*/
public static void setLookAndFeel(final String... intendedLAFIs) {
if (intendedLAFIs != null && intendedLAFIs.length > 0) {
final UIManager.LookAndFeelInfo[] installedLAFIs = UIManager.getInstalledLookAndFeels();
LAFILOOP:
for (String intendedLAFI : intendedLAFIs) {
for (final UIManager.LookAndFeelInfo lafi : UIManager.getInstalledLookAndFeels()) {
if (lafi.getName().equalsIgnoreCase(intendedLAFI)) {
try {
UIManager.setLookAndFeel(lafi.getClassName());
break LAFILOOP;
} catch (Exception e) {
continue LAFILOOP;
}
}
}
}
} else {
throw new IllegalArgumentException("intendedLAFIs is null or empty.");
}
}
/**
* Convenience method, compatible with Java 8 and 9.
*/
public static Dimension newDimension(final int w,
final int h) {
return new Dimension(scaleForComponent(w), scaleForComponent(h));
}
/**
* @param v E.g. the width of a component, or the size of a border.
* @return v scaled by the necessary display scaling factor for components and fonts, compatible with Java 8 and 9.
*/
public static int scaleForComponent(final double v) {
return (int) Math.round(v * GUISCALINGFACTOR_COMPONENTSANDFONTS);
}
/**
* @param v E.g. the width of a rectangle being drawn in a paint() or paintComponent() override.
* @return v scaled by the necessary display scaling factor for custom graphics, compatible with Java 8 and 9.
*/
public static int scaleForCustom(final double v) {
return (int) Math.round(v * GUISCALINGFACTOR_CUSTOMGRAPHICS);
}
/**
* E.g. when the GraphicsContext tells you the screen bounds. Which in Java 8 on 2x 4K desktop will be the full 4K numbers. But, same conditions except Java
* 9, will be half that. Even though you still need the full size.
* <p>
* But this is just an example case. The method was originally made for different cases.
*
* @param v E.g. the width as reported by a component. (Java 9 on 200% desktop reports e.g. 200, but the physical size is actually 400. This method returns
* 400 then.)
* @return v scaled so that it represents real physical pixels, compatible with Java 8 and 9.
*/
public static int scaleForRealComponentSize(final double v) {
return (int) Math.round(v * GUISCALINGFACTOR_REALCOMPONENTSIZE);
}
/**
* E.g. when you scaled the mouse location with the partner method, and now you want to use the mouse action result to scale/locate a window - then you need
* to UNDO the damage.
*/
public static int scaleForRealComponentSizeInverted(final double v) {
return (int) Math.round(v / GUISCALINGFACTOR_REALCOMPONENTSIZE);
}
public static Point scaleMouseEventCoordinatesForCustomGraphics(final Point mouseEventPoint) {
return new Point(scaleForRealComponentSize(mouseEventPoint.x),
scaleForRealComponentSize(mouseEventPoint.y));
}
/**
* @param font A font instance (Or null. Returns null.) whose size has been derived kinda like this: "new JLabel().getFont().getSize()" So it will look
* correct when used in components, no matter the current Java version. ......... WAIT WTF why does that look correct on Java 8
* ?!??!?!?!?!?!?!?! Anyway ... when you want to use THAT font in custom drawing, you'll have a bad time once you get on Java 9. Because
* components will have SMALLER font sizes than on Java 8 on a 200% desktop because their Graphics objects are scaled. But if you use custom
* drawing, you'll use the class GUIScalingCustomGraphics below, which reset the scaling to 1. But then the font is too small. THIS METHOD
* RETURNS THE SCALED FONT independent of the Java version.
* @return
*/
public static Font scaleFontForCustom(final Font font) {
if (font != null) {
return font.deriveFont(font.getSize2D() * (float) GUISCALINGFACTOR_REALCOMPONENTSIZE);
}
return null;
}
/**
* @param font A font instance (Or null. Returns null.) whose size is just a constant number in your source code, and which you want to use in an already
* normalized custom graphics context (meaning you used GUIScaling.GUIScalingCustomGraphics on it.) This font has to be scaled simply by the
* derived System scaling factor to look correct. This method does that.
* @return
*/
public static Font scaleMagicConstantFontForCustom(final Font font) {
if (font != null) {
return font.deriveFont(font.getSize2D() * (float) GUISCALINGFACTOR_SYSTEM);
}
return null;
}
/**
* For Java 9, but can blindly be used in Java 8, too. Ensures that the scaling of a paint(Component)()'s Graphics2D object is 1. Conveniently does the
* usual casting, too.
* <p>
* Also calculates the physical pixel width/height of the component, which is reported differently on Java 9 if the display scaling is not 100%.
*/
final public static class GUIScalingCustomGraphics {
final public double guiScalingFactor_manualDrawing = GUISCALINGFACTOR_CUSTOMGRAPHICS;
final public double guiScalingFactor_fontsThatLookCorrectInComponents = GUISCALINGFACTOR_FONTINCUSTOMGRAPHICSCONTEXT;
final public Component component; // Just for convenience. You can hand the whole instance down your paint call hierarchy.
final public int w; // The physical pixel width of the component.
final public int h; // dto. height
final public Graphics2D g; // Scale will be 1, even on Java 9 with a non-100% display scaling.
/**
* @param component NOT NULL. The component (e.g. JPanel or JFrame) whose paint() method you're overriding.
* @param graphics NOT NULL. The Graphics argument given to your paint() method.
*/
public GUIScalingCustomGraphics(final Component component,
final Graphics graphics) {
this.component = component;
w = scaleForRealComponentSize(component.getWidth());
h = scaleForRealComponentSize(component.getHeight());
g = (Graphics2D) graphics;
final AffineTransform t = g.getTransform();
final double xTrans = t.getTranslateX();
final double yTrans = t.getTranslateY();
t.setToScale(1, 1);
t.translate(xTrans, yTrans);
g.setTransform(t);
}
/**
* @param graphics NOT NULL. The Graphics argument given to your paint() method.
*/
public GUIScalingCustomGraphics(final Graphics graphics) {
component = null;
w = 0;
h = 0;
g = (Graphics2D) graphics;
final AffineTransform t = g.getTransform();
t.setToScale(1, 1);
g.setTransform(t);
}
/**
* @param x E.g. the width of a rectangle to be drawn.
* @return x scaled so that it represents real physical pixels, compatible with Java 8 and 9.
*/
public int scale(final double x) {
return (int) Math.round(x * guiScalingFactor_manualDrawing);
}
/**
* Scales the font and then sets it. Assumption: The given font looked correct in components. In Java 9, it would be TOO SMALL in custom graphics via
* this class. This method fixes that.
*
* @param font NULL = null will be returned and G's font will not change.
* @return returns the set font for convenience. NULL if your argument was null.
*/
public Font setFont(final Font font) {
final Font ret = font == null ? null : font.deriveFont(font.getSize2D() * (float) guiScalingFactor_fontsThatLookCorrectInComponents);
g.setFont(ret);
return ret;
}
@Override
public String toString() {
return "[GUIScalingCustomGraphics" +
" guiScalingFactor_manualDrawing=" + guiScalingFactor_manualDrawing +
" w=" + w +
" h=" + h +
" component=" + component +
" g=" + g +
']';
}
/**
* Convenience method that saves you unnecessary calls and code clutter. In your live painting method, you'll probably check first if your component has
* any pixels, aka if with AND height are at least 1. If they're not, you return before doing anything.
* <p>
* This method is a shortcut. Call this right at the beginning. If it returns true, you abort.
*/
public boolean isSizeZero() {
return w < 1 || h < 1;
}
}
/**
* A tiny rectangle will be filled with the current color and width/height of HAIRLINETHICKNESS.
*/
public static void drawPixel(final Graphics2D g,
final int x,
final int y) {
g.fillRect(x - GUIScaling.HAIRLINETHICKNESS_HALF,
y - GUIScaling.HAIRLINETHICKNESS_HALF,
GUIScaling.HAIRLINETHICKNESS,
GUIScaling.HAIRLINETHICKNESS);
}
final public static double JBUTTONFONTSIZE_ON_100PERCENTSCALE_JAVA8_W10_WITH_LOOKANDFEEL_WINDOWSORSYSTEMORXPLATFORMORWINCLASSIC = 11.0;
final public static float JBUTTONFONTSIZE_ON_UNKNOWNSCALE_UNKNOWNJAVA_UNKNOWNOS_WITH_LOOKANDFEEL_WINDOWSORSYSTEMORXPLATFORMORWINCLASSIC;
final public static double GUISCALINGFACTOR_SYSTEM; // The scaling set in the system.
final public static double GUISCALINGFACTOR_COMPONENTSANDFONTS; // The scaling necessary if you set component/font sizes yourself.
final public static double GUISCALINGFACTOR_CUSTOMGRAPHICS; // The scaling necessary if you want your custom graphics, too, to be scaled according to System settings.
final public static double GUISCALINGFACTOR_REALCOMPONENTSIZE; // The factor by which getWidth() and such return values have to be multiplied, because Java 9 reports them differently.
final public static double GUISCALINGFACTOR_FONTINCUSTOMGRAPHICSCONTEXT; // (This is exactly the custom graphics scaling probed by this class.) The factor by which a proper looking font would have to be scaled when used in custom graphics whose scale is 1. (Java 9 pre-scales it to e.g. 2 if Desktop is at 200%, then you reset that with the class above. Then the fonts that look right in the components will be TOO SMALL in the custom graphics. Use this factor / the method above to fix that.)
final public static int HAIRLINETHICKNESS; // A "hairline" would be a line with pixel thickness 1. However, if the GUI is scaled up, that should be a little thicker. This value will have a value of AT LEAST 1. If the GUI scaling of the system is 200%, the value will be 2. If it's 175%, the value will ALSO be 2 due to rounding.
final public static int HAIRLINETHICKNESS_HALF;
final public static double HAIRLINETHICKNESS_HALF_DOUBLE;
static {
if (!SwingUtilities.isEventDispatchThread()) { // This also makes sure an obfuscator doesn't remove this method and its calls.
throw new IllegalStateException("Must be initialized on Swing thread!");
}
System.err.println("Initializing GUI scaling ...");
GUIScaling.setLookAndFeelDefault();
JBUTTONFONTSIZE_ON_UNKNOWNSCALE_UNKNOWNJAVA_UNKNOWNOS_WITH_LOOKANDFEEL_WINDOWSORSYSTEMORXPLATFORMORWINCLASSIC =
new JButton().getFont().getSize2D(); // 21.0 on 200% desktop on Java 8 // 11.0 on 100% desktop on Java 8
final Integer[] paintScalingInPercent = new Integer[1];
final JDialog bruteForceJava9ScalingCheck = new JDialog((Frame) null, "", true) {
{
// setLocation(-1000, -1000); // Outamysight!
setLocation(100,
100); // else you might have compatibility problems (see stackoverflow where I posted this class)
final Runnable fallbackInCaseOlderJavaVersionDoesNotEndUpClosingThisWindow = () -> {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
SwingUtilities.invokeLater(() -> {
paintScalingInPercent[0] = 100;
dispose();
});
};
final Thread t = new Thread(fallbackInCaseOlderJavaVersionDoesNotEndUpClosingThisWindow);
t.setDaemon(true);
t.setName("GUI scaling detector fallback thread");
t.start();
}
@Override
public void paint(final Graphics graphics) {
final Graphics2D g = (Graphics2D) graphics;
final AffineTransform originalTransform = g.getTransform();
paintScalingInPercent[0] = (int) Math.round(originalTransform.getScaleX() * 100);
dispose();
}
};
bruteForceJava9ScalingCheck.setVisible(true); // This call blocks until dispose() is reached.
if (paintScalingInPercent[0] == null) {
throw new Error("Unexpected behavior: Modal dialog did not block!");
} else if (paintScalingInPercent[0] != 100) {
// Must be Java 9 (or newer?).
GUISCALINGFACTOR_SYSTEM = paintScalingInPercent[0] * 0.01;
GUISCALINGFACTOR_COMPONENTSANDFONTS = 1; // Java 9 does everything. The developer's considerations are made unnecessary/harmless by this "1".
GUISCALINGFACTOR_CUSTOMGRAPHICS = GUISCALINGFACTOR_SYSTEM;
GUISCALINGFACTOR_FONTINCUSTOMGRAPHICSCONTEXT = GUISCALINGFACTOR_SYSTEM;
} else {
// Either Java 8 (or older?) or scaling IS just at the normal 1 (100).
final double factorPreliminary = JBUTTONFONTSIZE_ON_UNKNOWNSCALE_UNKNOWNJAVA_UNKNOWNOS_WITH_LOOKANDFEEL_WINDOWSORSYSTEMORXPLATFORMORWINCLASSIC / JBUTTONFONTSIZE_ON_100PERCENTSCALE_JAVA8_W10_WITH_LOOKANDFEEL_WINDOWSORSYSTEMORXPLATFORMORWINCLASSIC;
// System.err.println("FIX MEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!");
// final double factorPreliminary = 1;
// If we just divide the two, we get 1.454545... on a 150% desktop, because the font sizes
// chosen by Java are integer values, so we experience a rounding error.
// The crappy but probably in most cases nicely working solution is: We round the result to .25 steps!
GUISCALINGFACTOR_SYSTEM = Math.round(factorPreliminary * 4) / 4d;
GUISCALINGFACTOR_COMPONENTSANDFONTS = GUISCALINGFACTOR_SYSTEM;
GUISCALINGFACTOR_CUSTOMGRAPHICS = GUISCALINGFACTOR_SYSTEM;
GUISCALINGFACTOR_FONTINCUSTOMGRAPHICSCONTEXT = 1; // No font scaling, the fonts used will look correct in custom scaling without extra treatment.
}
GUISCALINGFACTOR_REALCOMPONENTSIZE = GUISCALINGFACTOR_CUSTOMGRAPHICS / GUISCALINGFACTOR_COMPONENTSANDFONTS;
HAIRLINETHICKNESS = (int) Math.max(1, Math.round(GUISCALINGFACTOR_CUSTOMGRAPHICS));
HAIRLINETHICKNESS_HALF_DOUBLE = HAIRLINETHICKNESS * 0.5;
HAIRLINETHICKNESS_HALF = (int) Math.round(HAIRLINETHICKNESS_HALF_DOUBLE);
// System.err.println("GUISCALINGFACTOR_SYSTEM = " + GUISCALINGFACTOR_SYSTEM);
// System.err.println("GUISCALINGFACTOR_COMPONENTSANDFONTS = " + GUISCALINGFACTOR_COMPONENTSANDFONTS);
// System.err.println("GUISCALINGFACTOR_CUSTOMGRAPHICS = " + GUISCALINGFACTOR_CUSTOMGRAPHICS);
// System.err.println("GUISCALINGFACTOR_REALCOMPONENTSIZE = " + GUISCALINGFACTOR_REALCOMPONENTSIZE);
System.err.println("... done.");
}
}
关于java - 特定面板的 jdk 9 高 dpi 禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43057457/
我正在编写一个具有以下签名的 Java 方法。 void Logger(Method method, Object[] args); 如果一个方法(例如 ABC() )调用此方法 Logger,它应该
我是 Java 新手。 我的问题是我的 Java 程序找不到我试图用作的图像文件一个 JButton。 (目前这段代码什么也没做,因为我只是得到了想要的外观第一的)。这是我的主课 代码: packag
好的,今天我在接受采访,我已经编写 Java 代码多年了。采访中说“Java 垃圾收集是一个棘手的问题,我有几个 friend 一直在努力弄清楚。你在这方面做得怎么样?”。她是想骗我吗?还是我的一生都
我的 friend 给了我一个谜语让我解开。它是这样的: There are 100 people. Each one of them, in his turn, does the following
如果我将使用 Java 5 代码的应用程序编译成字节码,生成的 .class 文件是否能够在 Java 1.4 下运行? 如果后者可以工作并且我正在尝试在我的 Java 1.4 应用程序中使用 Jav
有关于why Java doesn't support unsigned types的问题以及一些关于处理无符号类型的问题。我做了一些搜索,似乎 Scala 也不支持无符号数据类型。限制是Java和S
我只是想知道在一个 java 版本中生成的字节码是否可以在其他 java 版本上运行 最佳答案 通常,字节码无需修改即可在 较新 版本的 Java 上运行。它不会在旧版本上运行,除非您使用特殊参数 (
我有一个关于在命令提示符下执行 java 程序的基本问题。 在某些机器上我们需要指定 -cp 。 (类路径)同时执行java程序 (test为java文件名与.class文件存在于同一目录下) jav
我已经阅读 StackOverflow 有一段时间了,现在我才鼓起勇气提出问题。我今年 20 岁,目前在我的家乡(罗马尼亚克卢日-纳波卡)就读 IT 大学。足以介绍:D。 基本上,我有一家提供簿记应用
我有 public JSONObject parseXML(String xml) { JSONObject jsonObject = XML.toJSONObject(xml); r
我已经在 Java 中实现了带有动态类型的简单解释语言。不幸的是我遇到了以下问题。测试时如下代码: def main() { def ks = Map[[1, 2]].keySet()
一直提示输入 1 到 10 的数字 - 结果应将 st、rd、th 和 nd 添加到数字中。编写一个程序,提示用户输入 1 到 10 之间的任意整数,然后以序数形式显示该整数并附加后缀。 public
我有这个 DownloadFile.java 并按预期下载该文件: import java.io.*; import java.net.URL; public class DownloadFile {
我想在 GUI 上添加延迟。我放置了 2 个 for 循环,然后重新绘制了一个标签,但这 2 个 for 循环一个接一个地执行,并且标签被重新绘制到最后一个。 我能做什么? for(int i=0;
我正在对对象 Student 的列表项进行一些测试,但是我更喜欢在 java 类对象中创建硬编码列表,然后从那里提取数据,而不是连接到数据库并在结果集中选择记录。然而,自从我这样做以来已经很长时间了,
我知道对象创建分为三个部分: 声明 实例化 初始化 classA{} classB extends classA{} classA obj = new classB(1,1); 实例化 它必须使用
我有兴趣使用 GPRS 构建车辆跟踪系统。但是,我有一些问题要问以前做过此操作的人: GPRS 是最好的技术吗?人们意识到任何问题吗? 我计划使用 Java/Java EE - 有更好的技术吗? 如果
我可以通过递归方法反转数组,例如:数组={1,2,3,4,5} 数组结果={5,4,3,2,1}但我的结果是相同的数组,我不知道为什么,请帮助我。 public class Recursion { p
有这样的标准方式吗? 包括 Java源代码-测试代码- Ant 或 Maven联合单元持续集成(可能是巡航控制)ClearCase 版本控制工具部署到应用服务器 最后我希望有一个自动构建和集成环境。
我什至不知道这是否可能,我非常怀疑它是否可能,但如果可以,您能告诉我怎么做吗?我只是想知道如何从打印机打印一些文本。 有什么想法吗? 最佳答案 这里有更简单的事情。 import javax.swin
我是一名优秀的程序员,十分优秀!