awt

Draw varying size rectangle with different orientation using rectangle 2D

霸气de小男生 提交于 2019-11-28 13:57:55
I want to draw a rectangle in a java application. I have used rectangle2d to draw a rectangle. I need the rectangle to vary size based on mouse drag. i.e. The size of the rectangle varies as I drag the mouse. I am currently able to draw only one type of the rectangle, i.e. When i drag the mouse towards down right of the screen. But i am unable to draw the other rectangles.for example. when the mouse is dragged top right of the screen. I am using a method called setRect that takes upper left x and y coordinates of the rectangle. But since when I drag the mouse top left, my upper left and upper

How to distribute AWTUtilities

∥☆過路亽.° 提交于 2019-11-28 13:57:05
I recently read the blog posts on Pushing Pixels that describe how to achieve native transparency and translucency with pure Java. The needed classes reside on com.sun.awt namely com.sun.awt.AWTUtilities. I was wondering how i could include the needed classes (not just this one) into my distro since the classes are available only when you have a jdk installed and you start the jvm through there. So the users of my program will not have the needed classes to run my program. Any ideas? Vineet Reynolds AWTUtilities, as the package implies is an implementation package and is subject to change. I

java game images loading very slowly

橙三吉。 提交于 2019-11-28 13:56:06
问题 I am trying to develop a game that imports the background images from a [100][100] matrix. The matrix will hold int values to correlate to what should be drawn on the background. A loop draws the images to the canvas and updates it based on key input from the user. Everything paints and moves fine however, it is very slow. Is there a better way to load the images rather than the way I am doing it? This is the main game class: package com.game.src.main; import java.awt.Canvas; import java.awt

Drawing the Cannabis Curve

眉间皱痕 提交于 2019-11-28 13:29:43
Inspired by Cannabis Equation from the Math site (it refers to the Wolfram Research Cannabis Curve ) I was wondering.. How would we draw this curve using Java-2D? import java.awt.*; import java.awt.geom.*; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import javax.swing.*; import java.io.File; /** Draws the CannabisCurve http://mathworld.wolfram.com/CannabisCurve.html Inspired by a question asked at: http://math.stackexchange.com/q/618786/38356 */ class CannabisCurve { double size = 80d; int pad = 5; CannabisCurve() { JOptionPane.showMessageDialog(null, new ImageIcon

Porting AWT graphics code to Android

余生长醉 提交于 2019-11-28 13:26:37
We would like to use some of our existing Java AWT graphics code on the Android platform. As far as I can tell, Android does not include any of the AWT classes -- no Graphics2D , Path2D , FontMetrics , etc. What is the best approach to port our drawing code to Android? Ideally, we would like to modify our code base to target both Android and generic Java. The android platform supports a small subset of awt. By small, I mean it supports awt fonts. Going from java swing (are you really just using awt as a standalone UI?) to Android is going to be a shock to the system. One defines Android's UI

Moving the visible area of a JScrollPane to a specific position

故事扮演 提交于 2019-11-28 13:17:57
问题 I am trying to simulate the movement of a debugging cursor using java. I am having problem to get the viewable area of the JScrollPane to the right position. Here is a picture I want to achive: I want to scroll only if the line I want to jump it is not visible. The calculation if it helps can by done using CodeDrowingPanel.NUMBER_OF_LINES and CodeDrowingPanel.FONT_SIZE the lines are painted on a panel using these constants. If I have to jump, the line I have to jump should be at the bottom. I

Creating a dot/pixel outside of a JFrame, any location on the screen

本小妞迷上赌 提交于 2019-11-28 13:08:12
I would like the be able to display points on the screen for my Java application. At some point I want to be able to let the user move the points and drag them around. Currently I am having trouble trying to draw a single dot/pixel on the screen outside of a JFrame. Any ways to draw outside of your JFrame area? You might create a full screen JFrame with full transparency, and draw to a panel or image on that. Much like this, which uses a custom panel to create a 'flashlight' effect for the mouse. We can see wherever the mouse is pointing, the rest of the screen is darkened. import java.awt.*;

Space button size on my layout keyboard won't resize

…衆ロ難τιáo~ 提交于 2019-11-28 12:53:31
I am working on a typing app which includes the a keyboard but I have found a bit hard to re-size the space button to make it wider than the other buttons.. This is the way I am displaying and organizing my layout.. I can resize the whole buttons but its NOT what I want.. the whole point is to be resize just the space bar.. :) import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import java.util.Arrays; import

Bufferstrategy not showing on java.awt.Frame

旧时模样 提交于 2019-11-28 12:46:36
问题 public void configure() { Frame frame = ctx.getFrame(); frame.setTitle("AstroCycles | By: Carlos Aviles"); frame.setResizable(false); frame.setLocationRelativeTo(null); frame.setFocusable(true); frame.setSize(WIDTH, HEIGHT); frame.addKeyListener(ctx.getKeyEventDispatcher()); frame.addWindowListener(ctx.getWindowEventDispatcher()); frame.addMouseListener(ctx.getMouseEventDispatcher()); frame.setVisible(true); frame.createBufferStrategy(3); frame.getBufferStrategy().getDrawGraphics().setColor

How to request focus synchronously in Swing?

僤鯓⒐⒋嵵緔 提交于 2019-11-28 12:42:43
When I call component.requestFocusInWindow() , Swing enqueues asynchronous FOCUS_GAINED and FOCUS_LOST events rather than synchronously transferring focus. As a workaround, it appears that DefaultKeyboardFocusManager is trying to simulate synchronously switching focus by delaying the dispatch of keyboard events until focus events have finished dispatching. But it appears that this isn’t working properly. Question: Is there any way to change focus synchronously in Swing? Is DefaultKeyboardFocusManager really trying to simulate synchronous focus, and is it seriously buggy? Is there a focus