jpanel

Java JPanel tiled background image

。_饼干妹妹 提交于 2019-12-18 05:06:19
问题 I currently have the code for creating a JOptionPane that tiles an image to the background no matter the size I set it to :) package test; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import javax.imageio.ImageIO; import javax.swing.*; public class TiledImage extends JPanel { BufferedImage tileImage; public TiledImage(BufferedImage image) { tileImage = image; } protected void paintComponent(Graphics g) { int width = getWidth(); int height = getHeight(); for (int x

JPanel Graphics clearing and repainting?

你。 提交于 2019-12-18 04:16:06
问题 I have a JPanel with a paintComponent() function. I'll call it once, then when the user clicks a different JButton , I'll set some flag and want to call this function again as it will do something slightly different after the flag is set. So here's what I'm wondering: how do I clear the existing stuff from paintComponent ? And to redraw, do I just call paintComponent again? Currently I'm trying the following: flag2 = true; repaint(); //I expect (want) paintComponent to be called again In

Java Swing: Enabling/Disabling all components in JPanel

落花浮王杯 提交于 2019-12-18 03:41:22
问题 I have a JPanel which contains a JToolbar (including few buttons without text) and a JTable and I need to enable/disable (make internal widgets not clickable). I tried this: JPanel panel = ....; for (Component c : panel.getComponents()) c.setEnabled(enabled); but it doesn't work. Is there a better and more generic solution to enable/disable all internal components in a JPanel? I have partially solved my problem using JLayer starting from the example here http://docs.oracle.com/javase/tutorial

Java Swing: Enabling/Disabling all components in JPanel

亡梦爱人 提交于 2019-12-18 03:41:18
问题 I have a JPanel which contains a JToolbar (including few buttons without text) and a JTable and I need to enable/disable (make internal widgets not clickable). I tried this: JPanel panel = ....; for (Component c : panel.getComponents()) c.setEnabled(enabled); but it doesn't work. Is there a better and more generic solution to enable/disable all internal components in a JPanel? I have partially solved my problem using JLayer starting from the example here http://docs.oracle.com/javase/tutorial

How to drag an image from one panel to other [closed]

萝らか妹 提交于 2019-12-17 22:28:46
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 6 years ago . I had created a frame and then panels in it. I had placed an image in one panel, now I need to drag that image to another panel. How could I do that. Please explain step by step as am a beginner. 回答1: Quick example using pure java, DragGestureListener , DropTargetAdapter and

.drawLine() issues and buffered image

两盒软妹~` 提交于 2019-12-17 21:28:38
问题 I have a paint programme and i have all the buttons and sliders done however i am having a problem with the actual painting itself. When I drag the cursor across the screen instead of an unbroken line I am getting almost a dotted line which i dont want. Here's the code for the MouseListener in the JPanel and BufferedImage : public void mouseDragged(MouseEvent e) { Graphics g=buffered.getGraphics(); g.setColor(mycol); Graphics2D graph=(Graphics2D)g; BasicStroke stroke=new BasicStroke(30);

How to draw multiple shapes on JComponent or Jpanel?

依然范特西╮ 提交于 2019-12-17 21:25:48
问题 I'm trying to build Paint app and I doing something wrong in DrawingArea class. The problem is when I try to draw second shape , the first shape or figure is auto deleting so I need to some idea about how to solve this.All answers acceptable. THANKS FOR HELP. There is part of DrawingArea.class codes : @Override // GETTING FIRST (STARTING) COORDINATE WHEN THE MOUSE PRESSED public void mousePressed(MouseEvent e) { oldX = e.getX(); oldY = e.getY(); repaint(); } @Override // GETTING RELEASED

Java Swing — Key Input with JPanel added to JOptionpane

江枫思渺然 提交于 2019-12-17 21:22:21
问题 When I run the code, the added Example1 class to the JOptionPane (in Frame) should get keyInput and then change the y value of the player instance (in example1), but it doesn't work. Also, how would I be able to rotate the ship on its axis and then move in the direction its facing? Currently it moves in the direction its rotated towards, but it rotates on what seems the coordinates 0,0. Frame import javax.swing.*; import java.awt.*; /** * Created by griffin on 12/7/2015. */ public class Frame

Java basic 2d game animation stutter

烂漫一生 提交于 2019-12-17 21:15:00
问题 So, I have been working on a 2d rpg for some time now and I can't seem to fix this one problem. The graphics seem to "jump" or stutter every few seconds for an unknown reason. This is getting quite annoying because I don't know what is causing it. Here is a very basic program I wrote that just has a red square that moves from one side of the screen to the other side. Even in this very basic program the square still stutters every few updates and I really can't figure it out for the life of me

How does one properly handle keypresses and repainting of a JComponent in the context of moving a ball around a screen?

ぐ巨炮叔叔 提交于 2019-12-17 20:53:21
问题 I thought I would try and write a program that would paint a ball, and when the arrow keys are pressed, would move the ball around the screen in the direction pressed. First I started off to try and make a program that would just do "UP" arrow key motion. I've looked around for a solution, and just can't figure out what's wrong with this code. I don't know if it's a problem with my input and action maps (i.e., a problem with the program recognizing key presses) or if it's a problem with how