jpanel

How to call a function when I click on a jPanel (Java)?

假装没事ソ 提交于 2019-12-13 13:13:52
问题 I'm working with Netbeans IDE in Java. I've a form with one JPanel. Each JPanel has a gridLayout 3x3 and in each place there is an image representing a number[0,1,2,3,4,5,6,7,8](the image is created used a custom class,not just fitting the image in a lab). I want to be able to exchange two images in the panel when the user click them (First click: no action , second click: switch the two images fitted in the jPanel Components). I already created a function exchangeComponents and with a test

How to reload a JPanel?

筅森魡賤 提交于 2019-12-13 12:06:45
问题 I'm a java newbie... I need to know how to reload a JPanel ? I extended the JPanel class and created a panel that will run in a cardlayout in an Applet. I want this panel to reload/refresh after the user clicks a button in this panel. I tried including the revalidate () and repaint () methods (methods I don't understand well) in the ActionListener for the button but nothing happened. Can anyone throw some light on how to correctly refresh the whole panel? 回答1: This works fine for me. But

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

Why can't I create a shape on jpanel?

让人想犯罪 __ 提交于 2019-12-13 10:34:37
问题 I'm working on java gui with socket programming.I want to create jpanel on the jframe with the parameters I send from the server and create random shapes in jpanel. I used this resource to draw shapes: https://github.com/AugustBrenner/Random-Draw-Shape/blob/master/DrawPanel.java my code in jframe is; public void starteGame(String received) { gamers.setText(received); String[] mParsed = received.split(" "); boolean filled = true; int width = Integer.parseInt(mParsed[2]); int height = Integer

how to put JavaFX in JPanel?

怎甘沉沦 提交于 2019-12-13 09:51:22
问题 I have a swing program and i am trying to incorporate a JavaFX bar graph in my program. How can I put it in a JPanel ? or Is there a way to put this code in a ActionListerner ? So I can run it after pressing a button. public static void start(Stage stage) { String judge1 = "Judge 1"; String judge2 = "Judge 2"; String judge3 = "Judge 3"; final CategoryAxis xAxis = new CategoryAxis(); final NumberAxis yAxis = new NumberAxis(); final BarChart<String,Number> bc = new BarChart<String,Number>(xAxis

JLayeredPane with gridlayout?

我是研究僧i 提交于 2019-12-13 09:50:08
问题 Is there a way for me to add buttons to the right side of my JLayeredPane? The layered pane contains a JPanel which represents a chess board and on top of this board I have JLabels representing chess pieces. I want basically another panel attached to the right side of the board which contains player information and buttons allowing for rematches/etc. What would be the best way to go about adding this panel? Here is a snippet of my code. The part which sets up the board panel inside the

Using Timer on a Paint Component

给你一囗甜甜゛ 提交于 2019-12-13 09:49:33
问题 I'm trying to make a visual representation of the traveling salesman problem using a genetic algorithm. I think I got most of it down but I need to slow the repaint() so i can see what's happening each iteration. Any idea how I should implement the actionPerformed() method while retaining the doGA() logic? class MyPanel extends JPanel implements ActionListener{ private final static int POINTWIDTH = 8; private final static Color POINTCOLOR = Color.RED; private final static Color LINECOLOR =

KeyListener not changing the JPanel

霸气de小男生 提交于 2019-12-13 07:34:40
问题 So i have created an extended version of JPanel and unfortunately it doesn't respond to any key typing. Could you tell me what the problem is? I searched all the others posts but i couldn't find my error. public class MyPanel extends JPanel implements ActionListener,KeyListener{ Timer tm=new Timer(5,this); int x=0,y=0 ,velX=0, velY=0; public MyPanel(){ tm.start(); addKeyListener(this); setFocusable(true); requestFocusInWindow(); } public void paintComponent(Graphics g){ super.paintComponent(g

JPanel Image Background Overlapping Other JPanel

你。 提交于 2019-12-13 07:26:57
问题 I got two JPanels, one is an image an other a form. I'm trying to put the first panel with the background image behind other (painting) but it doesn't work the panel background: public JPanel fundo() { JPanel bg = new JPanel(new BorderLayout()); try { Image backgroundImage = ImageIO.read(new File("C:/ceu.png")); setContentPane(new JPanel(new BorderLayout()) { @Override public void paintComponent(Graphics g) { g.drawImage(backgroundImage, 0, 0, null); } }); } catch (IOException e) { System.out

How to change Background color when i click a button

爷,独闯天下 提交于 2019-12-13 07:17:20
问题 My Problem is only just a little part that change color.I want to change the whole background when i click those buttons.I search already in google nothing happens. I Use Panel but it seems not only a little part that it can changes i want a whole background. import java.awt.event.MouseListener; import javax.swing.JOptionPane; import java.awt.event.*; /** * * * @author Christopher Porras * @Version 0.1 * @Doing GUI */ public class Button extends JFrame { private JButton bred; private JButton