jframe

My java(JFrame) player movement script won't work

﹥>﹥吖頭↗ 提交于 2021-02-08 09:20:27
问题 I am making a top down 2d survival game where the player must dodge projectiles from enemies in order to survive, but I've run into an issue that may, slightly influence the gameplay of my first real java project, that issue being that the player cannot move in any way shape or form and if the projectiles had of been implemented, then the player would lose immediately after spawning into this world. here is the code: package maximiza; import java.awt.*; import java.awt.event.KeyEvent; import

Is it possible to bring JFrame to front but NOT focus?

旧城冷巷雨未停 提交于 2021-02-06 15:17:26
问题 I'm writing a Java app (Swing GUI) that periodically pops up a JFrame. Is it possible somehow to bring the window to front (foo.setAlwaysOnTop(true) would be even better) but without having it focus? Some people move their eyes away from the screen from time to time to look at their keyboard while typing, and I'm sure that if this window would always capture the keyboard focus people would get really annoyed as it's causing them to lose quite a few keystrokes every time it pops up unnoticed.

JFrame doesn't take the actual screen size

浪子不回头ぞ 提交于 2021-02-05 11:56:18
问题 I have been trying to set the size of my JFrame to the exact same size of my screen (2256x1504). It also seems to take that size but when I display something the outcome is always bigger than intended. public class Frame extends JFrame { public Frame() { JPanel p = new JPanel(); int width = 2256; int height = 1504; Dimension size = new Dimension(width,height); p.setPreferredSize(size); p.setMinimumSize(size); p.setMaximumSize(size); p.setSize(size); this.setUndecorated(true); this

Add Jbutton to Jpanel

给你一囗甜甜゛ 提交于 2021-02-05 11:13:30
问题 can somebody tell me what is wrong with this code i am trying to add the buttons to my JPanel ArrayList<JButton> buttons = new ArrayList<JButton>(); JPanel createButtonspane(){ bpanel = new JPanel(); for(int i=0; i<10; i++){ buttons.add(new JButton(""+i)); bpanel.add(buttons); } return bpanel; } 回答1: This code does not compile because JPanel does not have an overload of add() which takes an array of JButton s, so you can not add a whole array of buttons to the JPanel (even if it was possible,

Add Jbutton to Jpanel

可紊 提交于 2021-02-05 11:10:16
问题 can somebody tell me what is wrong with this code i am trying to add the buttons to my JPanel ArrayList<JButton> buttons = new ArrayList<JButton>(); JPanel createButtonspane(){ bpanel = new JPanel(); for(int i=0; i<10; i++){ buttons.add(new JButton(""+i)); bpanel.add(buttons); } return bpanel; } 回答1: This code does not compile because JPanel does not have an overload of add() which takes an array of JButton s, so you can not add a whole array of buttons to the JPanel (even if it was possible,

Java: ImageIcon - image file updating but image icon in Java frame not

十年热恋 提交于 2021-02-05 09:24:12
问题 I have got a ImageIcon in a Jlabel in a JFrame (Java GUI). The ImageIcon should get updated based on pressing a Calculate button (i.e. calcButton.addActionListener(new ActionListener() ) with part of the code in the method: icon2 = new ImageIcon("M:\\Repos\\rtrans\\radTransPlot.png"); Plot1.setIcon(icon2); frame.add(Plot1,gc); frame.setVisible(true); The initial ImageIcon (icon1) is blank: public class RadTransGui { private ImageIcon icon1 = new ImageIcon("M:\\Repos\\rtrans\\radTransPlotEmpty

Dynamic JFreeChart TimeSeries

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-05 07:57:28
问题 [EDIT] Based on this example, I am now able to collect data and display it in a chart. I don't know exactly how to integrate that code that generates the chart into my application. /** @see http://stackoverflow.com/questions/5048852 */ public class Atol extends ApplicationFrame { private static final String TITLE = "Dynamic Series"; private static final String START = "Start"; private static final String STOP = "Stop"; private static final float MINMAX = 100; private static final int COUNT =

How to add a border to a rectangle in Java using setBorder and JFrame

戏子无情 提交于 2021-02-05 07:15:05
问题 I am trying to add a border to a Rectangle element and for some reason it will not work, is it not compatible with JFrame ? I can set my entire JFrame to having a border, but it can't find setBorder with my rectangles. Here is my code: package trivia; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.border

Java 五子棋小游戏

旧城冷巷雨未停 提交于 2021-02-03 01:09:31
package Day8_06; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; /** * * @author sky * */ public class Game { /** * 控件属性 */ private JFrame frame; // 五子棋游戏的窗口框架 private GameMap map; //

Java的五子棋实现

时光总嘲笑我的痴心妄想 提交于 2021-02-02 01:29:47
###<center>Java 五子棋 注:除机器人算法外其余借鉴于MLDN。 package MyFiveChess; import robot.*; import java.awt.*; import javax.swing.*; public class Gobang { public static void main(String[] args) { EventQueue.invokeLater(() -> { JFrame frame = new MyFiveChessFrame(new StupidRobot()); frame.setTitle("五子棋"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); }); } } 创建一个名为MyFiveChess的包,类名为Gobang,主方法中调用机器人类(StudipRobot)创建一个JFrame的框架,名为五子棋。 package MyFiveChess; import robot.*; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics;