paintcomponent

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

.gif image doesn't moves on adding it to the JTabbed pane

和自甴很熟 提交于 2019-12-17 04:07:32
问题 I have a JFrame. In that i have two containers i.e two JPanel. one Panel holds a image. other holds a JButton. Then these two are added to JTabbedPane. My problem is on using a .gif image the image becomes static as any other normal .jpg image. Can anyone help me with some more ideas? Here is my code: import java.awt.Component; import java.awt.Dimension; import java.awt.Frame; import java.awt.Graphics; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.awt.event

How does paintComponent work?

帅比萌擦擦* 提交于 2019-12-16 22:49:09
问题 This might be a very noob question. I'm just starting to learn Java I don't understand the operation of paintComponent method. I know if I want to draw something, I must override the paintComponent method. public void paintComponent(Graphics g) { ... } But when is it called? I never see anything like "object.paintComponent(g)" but still it is drawn when the program is running. And what is the Graphics parameter? Where is it from? Parameter must be supplied when the method is called. But as I

JPanel not displaying in JFrame after paint is called

℡╲_俬逩灬. 提交于 2019-12-13 20:51:19
问题 I am currently imlementing a simple GUI interface to interact with a Lego Mindstorm NXT. My current issue resides with a paint issue on my interface. When my MainUI loads it calls a method called GirdPanel() which sets up my GridPanel. The MainUI, which extends JFrame, then adds this panel to it's JFrame calling. Here is the full code for MainUI that matters for this problem. public MainUI(){ setSize(700, 600); PathPanel pathPanel = new PathPanel(controller); add(pathPanel, BorderLayout.WEST)

Java: mouseDragged and moving around in a graphical interface

落花浮王杯 提交于 2019-12-13 20:22:58
问题 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

Why is paintComponent() continuously and asynchronously being called without explicit repaint() call?

大憨熊 提交于 2019-12-13 16:42:30
问题 So this question has two parts, which I think may be related, and it's mostly abstract. Briefly, here's what I'm doing: I have a JFrame with a JPanel and some child JPanels each with 3 JButtons on it. I also created a JComponent called glassPanel for the JFrame (i.e. myJFrame.setGlassPane(glassPanel) ), that allows me to paint over the JPanels and buttons. (1) Essentially triggered by clicking all 3 buttons on a JPanel , glassPanel is set to Visible (which appears to then call paintComponent(

Java: selecting objects, that have been repainted [closed]

浪子不回头ぞ 提交于 2019-12-13 11:11:06
问题 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 . I am a student and having trubble making one of my projects this is only one bit of what my final project will actual be like but i am trying to compartmentalize it as much as possible. the specific problem I

Java thread and graphics2d

我们两清 提交于 2019-12-13 08:38:11
问题 i need a hint how to make my program to work properly. I created a class that extends from JComponent. I also managed to make the whole panel of white colors. Now i am trying to make that my thread Wolf will be painted on the JCOmponent and will move one time. Unfortunately my code dont works and i think its because wolf is not being painted on the white board. How to change the program to make it work. I will be grateful for help. public class Plansza extends JComponent implements

Java Swing Window

北城以北 提交于 2019-12-13 08:16:02
问题 import javax.swing.*; import java.awt.*; public class Main { public static void main(String[] args) { //load the card image from the gif file. final ImageIcon cardIcon = new ImageIcon("cardimages/tenClubs.gif"); //create a panel displaying the card image JPanel panel = new JPanel() { //paintComponent is called automatically by the JRE whenever //the panel needs to be drawn or redrawn public void paintComponent(Graphics g) { super.paintComponent(g); cardIcon.paintIcon(this, g, 20, 20); } }; /

I am trying to draw the line in the middle. I tried different coordinates

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-13 05:22:40
问题 Here is my paintComponent which contains the coordinates public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; g2.drawLine(-100,0,500,0); g2.drawLine(141,-500,141,500); g2.translate(getWidth()/2.0, getHeight()/2.0); g2.scale(1,-1); g2.rotate(45*Math.PI/180); Rectangle2D r = new Rectangle2D.Double(0,0,100,100); g2.fill(r); 回答1: It's a bit of a cheat, but... protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 =