jpanel

How To Add A MouseListener To A Frame

心已入冬 提交于 2019-12-14 00:23:15
问题 I want to add a mouselistener to mt JFrame frame but when i do frame.addMouseListener(this) i get an error that i cannot use this in a static method I am making an application that detects a click of the mouse then displays it in int clicks code import java.awt.BorderLayout; import java.awt.Color; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax

How to set a JPanel over a JFrame?

白昼怎懂夜的黑 提交于 2019-12-13 22:09:05
问题 I have a class named BoardGUI extended from JFrame , in a constructor I have made a JPanel with two buttons in it. I have added this panel into my frame. Whenever I run this program, buttons get invisible. As I bring my mouse cursor over the buttons they get visible. Code is as follows: public class BoardGUI extends JFrame { Play pieces; JButton a=new JButton("Undo"); JButton r=new JButton("replay"); JPanel jp=new JPanel(); public BoardGUI() { pieces = new Play(); setTitle("Checkers Game");

create JPanel after click the button /Java

て烟熏妆下的殇ゞ 提交于 2019-12-13 21:12:27
问题 I have a problem with my project. I would like to create new Panel in my Frame after click the button. Here's a part of a code: private class ComponentListener implements ActionListener { @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(newGameItem)) { System.out.println("dasda"); gamePanel = new GamePanel(); cont.add(gamePanel); } if (e.getSource().equals(stopItem)) { gamePanel.stopGame(); } } } GamePanel gamePanel; Container cont = this.getContentPane(); When

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)

How to make my MouseListeners work in a deserialized JPanel?

守給你的承諾、 提交于 2019-12-13 20:46:18
问题 I am writing a program which : Creates a JPanel that contains some Shape objects which can be MouseDragged around. Saves an object of this class in a binary file with an ObjectOutputStream Retrieves the objects from the binary file (with an ObjectInputStream) and adds it in a JFrame. My problem is that after my JPanel is retrieved (and therefore deserialized, I take it) and added to my JFrame , I cannot MouseDrag my shapes anymore. No clickable actions work actually. My teacher told me that I

Drawing in multiple JPanels contained in one JPanel

五迷三道 提交于 2019-12-13 20:04:11
问题 I have a class which extends JPanel which contain 3 other panels. I want to draw into the 3 panels. Here's what my code must be like, what am i doing wrong ? I just have an empty frame after execution. import java.awt.Color; import java.awt.FlowLayout; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Thumbnail extends JPanel { private JPanel bigPanel; private JPanel panelOne; private JPanel panelTwo; private JPanel panelThree; public Thumbnail() {

Swing Parent JFrame/JPanel unusable/clickable while child panel is loaded

荒凉一梦 提交于 2019-12-13 19:17:45
问题 I am loading a JFrame AdminFrame (with add user and addLocation button on it) when the user click's addUser button the new JFrame addUser loads and takes user information. When the information is submitted to server it takes some time(because server is web-based) during that time both of my panels got stuck...what i want is to make AdminFrame clickable and use-able so that user can add new user or can add location... Here is my AdminPanel s add button's template code...not writing original

JLayeredPane not drawing

僤鯓⒐⒋嵵緔 提交于 2019-12-13 18:14:41
问题 Good day, Hopefully this is a quick kill question. I am writing an application that uses JPanels and JLayeredPane inside a JFrame. On the initial start of my application, one of the panels does not show up until my mouse moves over the area where the panel should be. I even call the validate and repaint methods, but I am still able to display both panels together. Any suggestions? Thank you. Here is my JFrame class (which has the main method) import java.awt.Dimension; import javax.swing

JFrame and JPanel problems

北城余情 提交于 2019-12-13 15:45:53
问题 I am attempting to make a program for a local bagel shop that sells pastries, bagels, and coffee. I am having trouble implementing the panels that I have made into the JFrame any help understanding how to make my JFrame look like this would be helpful http://kepler.covenant.edu/COS150/Bagel_files/image002.jpg Once I have this working I hope to have the middle set of panels change depending on which product is selected. I am not entirely sure how to make the buttons and panels talk to one

JPanel error - J Component cannot be resolved

ぐ巨炮叔叔 提交于 2019-12-13 15:13:36
问题 I've library of JRE System Library JRE 1.8.x Here an error goes with my lines. Error: The type javax.swing.JComponent cannot be resolved. It is indirectly referenced from required .class files How can I remove this error? Here is screenshot: http://i60.tinypic.com/15z1n2h.png Kindly tell me steps. I am new to Java. Thanks in advance. . . Package Snake **Class RenderPanel package snake; import javax.swing.JPanel; import java.awt.Graphics; import javax.swing.JComponent; @SuppressWarnings(