awt

Pacman open/close mouth animation

放肆的年华 提交于 2019-12-17 07:41:20
问题 I want to make the pacman open/close mouth animation using the easiest method. Here is my recent code: The problem is, nothing is happening? package ordner; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class PacMan implements ActionListener { private JFrame frame; private DrawPanel panel; private void initGui() { frame = new JFrame("Pacman"); frame.setDefaultCloseOperation(JFrame

Java: mouseDragged and moving around in a graphical interface

时光毁灭记忆、已成空白 提交于 2019-12-17 06:54:12
问题 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

java drag and drop

≯℡__Kan透↙ 提交于 2019-12-17 05:14:20
问题 I try to get familar with drag and drop in java but all the tutorials I found were... (getting me angry) All I want is to drag a "PublicUserLabel" from a JList (included in a selfmade JPanel called "UserPanel") and drop it in a selfmade class inerited from JTabbedPanel. It is very important to drag the object itself and not its stringrepresentation!!! That is what I have so far: PublicUserLabel public class PublicUserLabel extends JLabel implements DragSourceListener, DragGestureListener,

Copying to the clipboard in Java [duplicate]

家住魔仙堡 提交于 2019-12-17 04:22:28
问题 This question already has answers here : Copying text to the clipboard using Java (4 answers) Closed 10 months ago . I want to set the user's clipboard to a string in a Java console application. Any ideas? 回答1: Use the Toolkit to get the system clipboard. Create a StringSelection with the String and add it to the Clipboard . Simplified: StringSelection selection = new StringSelection(theString); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents

Copying to the clipboard in Java [duplicate]

心不动则不痛 提交于 2019-12-17 04:22:27
问题 This question already has answers here : Copying text to the clipboard using Java (4 answers) Closed 10 months ago . I want to set the user's clipboard to a string in a Java console application. Any ideas? 回答1: Use the Toolkit to get the system clipboard. Create a StringSelection with the String and add it to the Clipboard . Simplified: StringSelection selection = new StringSelection(theString); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents

A rotated square panel in Java GUI

a 夏天 提交于 2019-12-17 04:08:24
问题 I wonder if it is possible to implement a GUI panel (possibly JPanel) that is of square shape but rotated 90 degrees. Obviously, there will be a top-level container which contains this panel, and visually the main panel is this rotated square panel within. More specifically, I would divide a panel (called 'A') into 4 equal square sub-panels, and fill these sub-panels with JLabels, for which I am thinking to use GridLayout. And lastly, I would rotate 'A' 90 degrees to give what I want. From my

java multiple graphics [closed]

跟風遠走 提交于 2019-12-17 03:44:07
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . Okay so I have been working on this code for awhile that shows how the sorting algorithms work. Right now I have it working where it sorts multiple graphs with the same sort but I need each graph to do a

Graphics rendering in title bar

拈花ヽ惹草 提交于 2019-12-17 02:51:32
问题 The graphics keep rendering in the title bar. I use a buffered Image encapsulated in a jlabel and use the resultant graphic objects to draw rectangles in my code. This is the important part of the jframe class constructor: super(); BufferedImage image=new BufferedImage(680,581,BufferedImage.TYPE_INT_ARGB); m_graphicsObject =image.getGraphics(); JLabel label=new JLabel(new ImageIcon(image)); // buttons, mouse events and other controls use listeners to handle actions // these listener are

Image/Graphic into a Shape

北城余情 提交于 2019-12-17 02:49:11
问题 I was wondering whether there is any way to convert an image/graphic into a Shape ? For example, can I convert the outline of a motorcycle shape into a Shape so I can then use it in Java? I know you can do it with normal squares or with rounded corners, polygons, etc. But is there a way to do a custom shape? 回答1: motorcycle.jpg motorcycle-03.png ImageOutline.java This code requires some patience (when running). import java.awt.*; import java.awt.image.BufferedImage; import java.awt.geom.Area;

What does .pack() do?

↘锁芯ラ 提交于 2019-12-17 02:31:51
问题 I am learning about JPanel and GridLayout , this snippet of code will produce a simple JPanel with 6 buttons package testing; import java.io.*; import java.util.*; import java.security.*; import javax.xml.bind.DatatypeConverter; import java.lang.*; import java.awt.*; import javax.swing.*; public class Testing { public static class GridPanel extends JPanel { public GridPanel() { setLayout(new GridLayout(2,3)); setBackground(Color.GREEN); this.setPreferredSize(new Dimension(500,500)); JButton