awt

Can't get NetBeans to access “FigurePanel” in Java

别来无恙 提交于 2019-12-12 01:34:15
问题 I'm a beginner when it comes to Java and I'm following the instructions from a book. I am going to create a FigurePanel with the following code: import java.awt.*; import javax.swing.*; public class TestFigurePanel extends JFrame{ public TestFigurePanel() { setLayout(new GridLayout(2, 3, 5, 5)); add(new FigurePanel(FigurePanel.LINE)); } } But at the "add(new FigurePanel(FigurePanel.LINE));" I get the following error: "Cannot find symbol: Symbol: class FigurePanel class: TestFigurePanel" I

Adding a canvas to a panel doesn't show the canvas?

被刻印的时光 ゝ 提交于 2019-12-12 01:12:02
问题 First of all: sorry, if this question was asked before, but I cannot seem to find an answer anywhere, so here we go: I am trying to get a canvas element to show while it being added to a panel with a titled border around the panel. Here is my code. public class TestClass extends JFrame{ private TestClass() { GuiCanvas canvas = new GuiCanvas(); setTitle("TestClass"); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(1300, 800); Border menuBorder = BorderFactory.createTitledBorder( BorderFactory

Paint on panel during runtime

只愿长相守 提交于 2019-12-12 00:48:43
问题 I have a panel on which I want to draw stuff. Painting on it when it is beeing created is no problem. canvas = new Panel() { public void paint(Graphics g) { g.setColor(Color.WHITE); g.drawLine(0, 0, 10, 10); } }; But then I want to draw on it during runtime. By instinct, I've created something like this: Graphics g = canvas.getGraphics(); g.setColor(Color.GREEN); g.drawLine(10, 10, 20, 20); canvas.paint(g); Sadly, this doesn't work. This is probably a simple question but I cannot find a

Simulate keypress in java to write user inputs to another application

妖精的绣舞 提交于 2019-12-12 00:34:26
问题 I am developing a virtual keyboard application. Everything works fine except that what ever i write is written into the present application only not the one that is running behind. I fell this is because ROBOT class in java only works for the application context that creates it. Is there a work around for this? Here is the code, i am trying to write ls in the terminal that is behind my java application: Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_ALT); robot.keyPress(KeyEvent.VK_TAB

Undo method for a paint program [duplicate]

妖精的绣舞 提交于 2019-12-11 21:25:42
问题 This question already has answers here : Extending Swing's UndoManager to provide repeat and multiple undo/redo (2 answers) Closed 5 years ago . I am trying to create a little drawing pad in one of my programs. This is the class: class DrawPad extends JComponent { Image image; Graphics2D graphics; int currentX, currentY, oldX, oldY; public DrawPad() { setDoubleBuffered(false); addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { oldX = e.getX(); oldY = e

Chat program freezes JFrame

旧城冷巷雨未停 提交于 2019-12-11 20:33:59
问题 I'm writing a simply chat client and am moving it over to a nice GUI. The constructor for the server side (client side is android) contains a list that's in the JFrame, and the first part of the server runs, but then the entire frame locks up. Does anyone see the issue? Sorry for the relatively disorganized, not cleanly commented code... Server: import java.awt.List; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import

Is there a more efficient way to rotate images in Java than AffineTransform?

半腔热情 提交于 2019-12-11 20:13:55
问题 I've looked around for ways to rotate BufferedImage s in Java and all I have found is AffineTransform . That's fine, but it seems like a bit of overkill if all I want to do is rotate 90 degrees. Would it be more efficient to just do it pixel-by-pixel? Is there some other method I could use? 回答1: From the Javadoc of the class you mention: Handling 90-Degree Rotations In some variations of the rotate methods in the AffineTransform class, a double-precision argument specifies the angle of

move image from one panel to another

怎甘沉沦 提交于 2019-12-11 20:06:36
问题 I have Code where I can move image. Everything works well. here I have only one ImagePanel (children of JPanel) on the frame. Questions: I need to drag and drop image from one JPanel to another JPanel. Then I need to move dragged image to current panel . Can you give me an example code, please? class ImagePanel extends JPanel { int x, y; BufferedImage image; ImagePanel() { setBackground(Color.white); setSize(450, 400); addMouseMotionListener(new MouseMotionHandler()); Image img = getToolkit()

Creating Gridbag Layout

≯℡__Kan透↙ 提交于 2019-12-11 19:42:26
问题 I'm trying to make a gridbaglayout, to simply have the label atop the textbox atop the textview in a vertical window, but I'm getting the exception Exception in thread "main" java.lang.IllegalArgumentException: cannot add to layout: constraints must be a GridBagConstraint at java.awt.GridBagLayout.addLayoutComponent(GridBagLayout.java:685) at java.awt.Container.addImpl(Container.java:1072) at java.awt.Container.add(Container.java:957) at javax.swing.JFrame.addImpl(JFrame.java:540) at java.awt

Animated GIF in Splashscreen

坚强是说给别人听的谎言 提交于 2019-12-11 19:25:50
问题 I have a JAR file generated by an ANT script with the following code in it: <manifest> <attribute name="Main-Class" value="org.epistasis.exstracs.Main"/> <attribute name="Class-Path" value="."/> <attribute name="SplashScreen-Image" value="logo_anim.gif"/> </manifest> <!--Some code--> <zipfileset dir="." includes="logo.png"/> <zipfileset dir="." includes="logo_anim.gif"/> <zipfileset dir="." includes="icon.png"/> When I run the JAR file, no splash screen is generated. I verified that the GIF