awt

Triangle Draw Method

放肆的年华 提交于 2019-11-27 03:11:30
问题 I have trouble drawing a triangle with the draw(Graphics g) method in Java. I can draw a rectangle like so: public void draw(Graphics g) { g.setColor(colorFill); g.fillRect(p.x, p.y, width, height); g.setColor(colorBorder); g.drawRect(p.x, p.y, width, height); drawHandles(g); Where p represents "the top left corner of the shapes". How would I draw the triangle in the same manner? Could someone give me an example for a standard triangle? 回答1: There is not a drawTriangle method neither in

java draw line as the mouse is moved

自作多情 提交于 2019-11-27 03:00:27
问题 I would like to add a feature to my application which allows the user to draw a straight line by clicking the mouse at the start location and releasing it at the end location. The line should move as the mouse moves until it is finally released; similar to the way that a line can be drawn using the Microsoft Paint application. How can implement this so that the line is repainted as it moves without repainting other things that may already be drawn in that rectangular area? 回答1: Try this..

How to move a mouse smoothly throughout the screen by using java?

不问归期 提交于 2019-11-27 02:59:04
问题 There is a mouseMove()method that makes the pointer jump to that location. I want to be able to make the mouse move smoothly throughout the screen. I need to write a method named mouseGLide() which takes a start x, start y, end x, end y, the total time the gliding should take, and the number of steps to make during the glide. It should animate the mouse pointer by moving from (start x, start y) to (end x, start y) in n steps. The total glide should take t milliseconds. I don't know how to get

Java: mouseDragged and moving around in a graphical interface

℡╲_俬逩灬. 提交于 2019-11-27 02:13:15
newbie programmer here. I'm making a program that renders user-inputted equations in a Cartesian coordinate system. At the moment I'm having some issues with letting the user move the view around freely in the coordinate. Currently with mouseDragged the user can drag the view around a bit, but once the user releases the mouse and tries to move the view again the origin snaps back to the current position of the mouse cursor. What is the best way to let the user move around freely? Thanks in advance! Here's the code for the drawing area. import java.awt.Color; import java.awt.Graphics; import

Why are my items not showing up in JFrame?

微笑、不失礼 提交于 2019-11-27 02:03:18
I'm fairly new to JFrame and I want to know why my items are not showing up on the window. I know i dont have a ActionHandler but I just want my textfield's to show up on my window. Here's my code: import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class FirstGUI extends JFrame{ public void GUI(){ setTitle("Welcome"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); setSize(600,600); JLabel title = new JLabel(); title.setText("Apple Inc. Member Login Port");

Using awt with android

混江龙づ霸主 提交于 2019-11-27 01:58:06
I have a Java Swing application which draws diagrams. It uses Graphics2D calls and awt objects such as Rectangle etc. At some point I might want to port this to Android. I understand that I can't use Graphics2D on Android, but can I still use the awt Rectangle, Font, Color (etc) classes. What I want to do is to isolate any code changes between the swing version and the Android version by adding an emulation layer so my Graphics2D calls can be converted to Android drawing calls. Is this feasible? Just to be clear, I am not too worried about the Swing UI side of things (the UI is minimal and can

Copying to global clipboard does not work with Java in Ubuntu

不羁岁月 提交于 2019-11-27 00:59:33
问题 The following code from a standalone application works in ubuntu: import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.UnsupportedFlavorException; import java.io.IOException; public class ClipboardTest { public static void main(String[] args) throws Exception { Clipboard clipBoard = Toolkit.getDefaultToolkit().getSystemClipboard(); // print the last copied thing

Create GUI using Eclipse (Java) [duplicate]

醉酒当歌 提交于 2019-11-27 00:11:25
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Best GUI designer for eclipse? Is there any Eclipse Plugin tool(s) who can help to create Graphical User Interface for (swing, awt or swt), because I'm tired of writing everytime the code of Panels, Labels, ... Thanks 回答1: Yes. Use WindowBuilder Pro (provided by Google). It supports SWT and Swing as well with multiple layouts (Group layout, MiGLayout etc.) It's integrated out of the box with Eclipse Indigo, but

Print the whole program layout

家住魔仙堡 提交于 2019-11-26 23:42:53
问题 I have made a Java program ( JFrame based) using Netbeans, I would like to know if it is possible to print the layout of the program I wish to have a button and set the function to "print" and the final layout of the frame will be printed, is it possible? If yes, any reference source? 回答1: This will depend on what it is you hope to achieve. You could simply print the contents of the frame to a BufferedImage . This allows you to control what you want to capture, in that you could print the

Swing components are light-weight?

ぐ巨炮叔叔 提交于 2019-11-26 23:36:27
问题 Whenever I read about Swing they say they are light weight components. So I just googled Swing and found that it means Swing does not depend on native peers. Is that why they are called "light weight" ? I mean by light weight I thought maybe the Swing components occupy less memory than the AWT components. Isn't that so? 回答1: Swing is considered lightweight because it is fully implemented in Java, without calling the native operating system for drawing the graphical user interface components.