awt

Drawing lines with mouse on canvas : Java awt

允我心安 提交于 2019-11-30 20:37:46
The attempt is to enable drawing of figures(a line for now) with mouse on the awt canvas . Iam trying out java graphics for the first time . So not sure how to go about it . This is my first attempt : package def.grafi; import java.awt.Canvas; import java.awt.Frame; import java.awt.Graphics; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Dra { Frame f = new Frame(); public void disp() { f.setBounds(100, 100, 200, 200); MosL ml = new MosL(); Can

Unregister font with GraphicsEnvironment?

冷暖自知 提交于 2019-11-30 20:08:11
I recently found out how to register a TTF font with the local GraphicsEnvironment, s.t., for my use case (SVG-to-PNG transcoding), Apache Batik may recognize the font: import java.awt.Font; import java.awt.FontFormatException; import java.awt.GraphicsEnvironment; // [...] GraphicsEnvironment lge = GraphicsEnvironment.getLocalGraphicsEnvironment(); try { Font font = Font.createFont(Font.TRUETYPE_FONT, fontFile); lge.registerFont(font); } catch (FontFormatException e) { logger.warn(e.getMessage(), e); } catch (IOException e) { logger.warn(e.getMessage(), e); } However, I was wondering if I

Java: use clipboard to copy-paste java objects between different instances of same application

老子叫甜甜 提交于 2019-11-30 19:57:49
I am trying to implement copy-paste of objects between different instances of same application. Currently it works only in one application (I mean, copy and paste in the same instance of application), but does not work between different instances. Copying code: // MyObject is a class of objects I want to copy/paste; // MyObjectSelection is a class that impements Transferable and ClipboardOwner interfaces Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); MyObject data = new MyObject(selectedItems); MyObjectSelection dataSelection = new MyObjectSelection(data); clipboard

Taking screenshot in Java (Robot, code working but not with external full screen application)

久未见 提交于 2019-11-30 19:54:03
问题 I am using the following code for taking a screenshot: Robot robot = new Robot(); BufferedImage image = robot.createScreenCapture(screenRectangle); ImageIO.write(image,"png", file); This code is running good. It takes screen shots of my desktop when I run the program, etc. However, when I try to run first some game, application in full screen , it doesn't work properly. It renders either black screen, either the same "initial" picture. Is this problem known, and how to fix this please? Second

Does AWT/Swing cancel painting operations if the monitor is off?

三世轮回 提交于 2019-11-30 18:45:36
I am experiencing a problem with Swing that only occurs when the computer monitor is powered off, but my Swing application continues to run in the background. It seems that whenever the monitor is off, Swing/AWT cancels all painting operations, leading to a number of display issues in the GUI that are visible as soon as the monitor turns back on. For example, when I turn off the monitor using a custom JNI function and subsequently open a simple message dialog, the message dialog is blank when the monitor turns back on: But it paints correctly after the next repaint: Is this the expected

Where is the Java Swing counterpart of “GetMessage()” loop?

做~自己de王妃 提交于 2019-11-30 18:23:16
问题 I did some Win32 GUI programming several years ago. Now I am using Java Swing. Just out of curiosity, where is the Swing counterpart of Win32 message loop logic? In Win32, it is achieved with the API GetMessage(). I guess it must have been wrapped deeply somewhere. 回答1: Overview The following diagram broadly illustrates how Swing/AWT works on the Windows platform: Our Listeners ▲ │ (Events dispatched to our code by EDT) ╭ ◀─────────┴───────────╮ │ Event Dispatch Thread │ ╰───────────▲────────

BeginnerBook Java 教程

烈酒焚心 提交于 2019-11-30 18:15:30
来源: ApacheCN BeginnerBook 翻译项目 译者: 飞龙 协议: CC BY-NC-SA 4.0 贡献指南 本项目需要校对,欢迎大家提交 Pull Request。 请您勇敢地去翻译和改进翻译。虽然我们追求卓越,但我们并不要求您做到十全十美,因此请不要担心因为翻译上犯错——在大部分情况下,我们的服务器已经记录所有的翻译,因此您不必担心会因为您的失误遭到无法挽回的破坏。(改编自维基百科) 目录 Java 基础知识教程 Java 编程简介 Java 虚拟机(JVM),JDK 差异,JRE 和 JVM - 核心 Java 如何编译和运行您的第一个 Java 程序 Java 中的变量 Java 中的数据类型 Java 中的运算符 Java 中的 if 和 if-else 语句 Java 中的 switch-case 语句 Java 中的 for 循环 Java 中的 while 循环 Java 中的 do-while 循环示例 Java continue 语句 Java 中的 break 语句 Java OOP 教程 Java 中的构造函数 - 一个完整的研究 Java - 静态类,块,方法和变量 Java 编程中的继承 Java 中的继承类型:单一,多重,多级和混合 OOP 概念 - 什么是 java 中的聚合? OOP 概念 - java 中的关联是什么? java

IntelliJ IDEA优化设置/取消自动保存

房东的猫 提交于 2019-11-30 17:24:39
1.修改JVM参数 (IntelliJ IDEA 10.0.1包含以上版本不需要设置) -Xms715m -Xmx1024m -XX:MaxPermSize=256m 修改idea.exe.vmoptions配置文件调整以下内容: -Xms256m -Xmx384m -XX:MaxPermSize=128m -XX:NewRatio=4 -Xss128k -Dsun.awt.keepWorkingSetOnMinimize=true -server -Xms256m设置初时的内存数,你需要设置一个合理的值, 增加该值可以提高Java程序的启动速度。如果你的内存够大,如2G,可以设置到400m。 -Xmx384m设置最大内存数,提高该值,可以减少内存Garage收集的频率,提高程序性能。 -Dsun.awt.keepWorkingSetOnMinimize=true 可以让IDEA最小化到任务栏时依然保持以占有的内存,当你重新回到IDEA,能够被快速显示,而不是由灰白的界面逐渐显现整个界面,加快回复到原界面的速度。 -server控制内存garage方式,这样你无需在花一到两分钟等待内存garage的收集。 2.优化文件保存和工程加载 取消“Synchronize file on frame activation” 和“Save files on framedeactivation

AWT Frame in full-screen exclusive mode gets minimized on windows dialog popup

我是研究僧i 提交于 2019-11-30 16:43:55
i am developing an application which uses an awt frame in full-screen exclusive mode. Everythings works fine until a windows popup gets visible. This will steal the focus and my application will be minimized. Here is my init code of the frame: if (ApplicationConfig.getInstance().useFullscreenMode()) { frame.setUndecorated(true); frame.setResizable(false); if (monitor.isFullScreenSupported()) { monitor.setFullScreenWindow(frame); if (monitor.isDisplayChangeSupported()) { DisplayMode defaultMode = new DisplayMode( (int) appDimension.getWidth(), (int) appDimension.getHeight(), 32, DisplayMode

AWT Frame in full-screen exclusive mode gets minimized on windows dialog popup

情到浓时终转凉″ 提交于 2019-11-30 16:23:56
问题 i am developing an application which uses an awt frame in full-screen exclusive mode. Everythings works fine until a windows popup gets visible. This will steal the focus and my application will be minimized. Here is my init code of the frame: if (ApplicationConfig.getInstance().useFullscreenMode()) { frame.setUndecorated(true); frame.setResizable(false); if (monitor.isFullScreenSupported()) { monitor.setFullScreenWindow(frame); if (monitor.isDisplayChangeSupported()) { DisplayMode