jframe

java fullscreen window with transparency

假如想象 提交于 2020-01-01 08:59:30
问题 I am trying to create a fullscreen window that cover the whole screen using Java. This window must also have some transparency (about 30%-50% transparent). When saying whole screen, I do mean it cover everything (including the dock/taskbar/menubar in OSX/Linux/Windows), and when I say with transparancy, I mean a real-time transparancy and not just a hacked screenshot. Here is what I am aware-of/tried: Using Java Fullscreen API: while it creates a true fullscreen, you cannot have some

How to put a JButton at a specific location?

安稳与你 提交于 2019-12-31 07:20:29
问题 I know that there are already very similar questions to my question on stackoverflow, but neither one of them answers my question. I want to put my JButton on a specific location on my JFrame in JAVA. Here is my Code: public class DetectMotion extends JFrame { private JLabel label = null; public DetectMotionExample() { JPanel pnlButton = new JPanel(); label = new JLabel(nothing); JButton btn = new JButton("Close"); pnlButton.setLayout(new BorderLayout()); setTitle("Motion Detector");

Java Scanner issues (JFrame)

↘锁芯ラ 提交于 2019-12-31 07:03:09
问题 I am trying to use a scanner to edit the level of my tower defense game. However it will not update the level (the tile images) to that of the custom file (0 is grass 1 is stone -1 is nothing, etc.). I have found the error but how do i fix it, what do i need to add/change to get rid of this? java.lang.NullPointerException at Levels.loadLevels(Levels.java:11) at Window.define(Window.java:28) at Window.paintComponent(Window.java:44) line 11: for(int y=0;y<Window.room.block.length;y++) { line 28

Java Scanner issues (JFrame)

落爺英雄遲暮 提交于 2019-12-31 07:02:12
问题 I am trying to use a scanner to edit the level of my tower defense game. However it will not update the level (the tile images) to that of the custom file (0 is grass 1 is stone -1 is nothing, etc.). I have found the error but how do i fix it, what do i need to add/change to get rid of this? java.lang.NullPointerException at Levels.loadLevels(Levels.java:11) at Window.define(Window.java:28) at Window.paintComponent(Window.java:44) line 11: for(int y=0;y<Window.room.block.length;y++) { line 28

Drawing Canvas on JFrame

血红的双手。 提交于 2019-12-31 06:18:50
问题 I'm trying to draw simple shapes with Canvas, in this class I've set the painting public class Game extends Canvas{ //FIELDS public int WIDTH = 1024; public int HEIGHT = WIDTH / 16 * 9; //METHODS public void start(){ Dimension size = new Dimension (WIDTH, HEIGHT); setPreferredSize(size); paint(null); } public void paint(Graphics g){ g.setColor(Color.GREEN); g.fillRect(0, 0, WIDTH, HEIGHT); g.setColor(Color.BLACK); g.fillOval(100, 100, 30, 30); } } And in this the Window public class MainW {

Overriding the paint() method

ぐ巨炮叔叔 提交于 2019-12-31 05:29:06
问题 I've got a beginner question here that I was hoping someone with some Java experience could help me with. Currently taking an intro to OOP course focused on Java. My instructor is currently covering awt and swing, specifically the need to override the paint method so that graphics are redrawn when a window is resized, etc. I like to do as much outside reading as possible, and my concern is that the examples that my professor gives involve things that I've read are not best practices. To get

Modifying independent JPanels from the JFrame

淺唱寂寞╮ 提交于 2019-12-31 04:43:08
问题 I've got a JFrame with two separate JPanels. One of the JPanels is filled with JButtons while the other has a couple of text fields. I added mouse listeners to the buttons via the JFrame and I want to make it so that when an event is fired from the first JPanel, the text fields in the second JPanel are changed. The two panels have their own classes. How would I go about doing this? 回答1: Use MVC, Model-View-Control, separation of concerns. Have the Control, which holds your listeners, change

How can I check when a JFrame has been closed?

若如初见. 提交于 2019-12-31 04:22:14
问题 How do I check when JFrame window is closed? MediaPanel mediaPanel=new MediaPanel(); JFrame_of_subtitle frame=new JFrame_of_subtitle(mediaPanel); JPanel panel=new JPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 回答1: You will add WindowListener to your frame. WindowListener has a windowClosing callback function which will be invoked when your frame is being closed. You can see this tutorial for sample code. 来源: https://stackoverflow.com/questions/10370064/how-can-i-check-when-a

How to set the JFreeChart X axis data titles?

江枫思渺然 提交于 2019-12-31 04:09:33
问题 Attached my code snippet here, I am using XYStepChart from chart factory. The x-axis scale at output for the code is being displayed in scale of eg: 05:30:00:00 , 05:30:00:01 , 05:30:00:00 . But I need in values like 1,2,3,4. package org.jfree.chart.demo; import java.awt.BasicStroke; import java.awt.Color; import org.jfree.chart.ChartFactory; import org.jfree.chart.ChartFrame; import org.jfree.chart.JFreeChart; import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot;

Why does my jFrame update only after I resize the window?

风流意气都作罢 提交于 2019-12-31 03:27:07
问题 I understand that when you add/remove a component, you need to revalidate() and then repaint() . However, I am changing the state of my polygon. Initially, the image is shown, however when I press the left and right keys, the image does not move. If I move the window, the gui is updated. Why doesn't it update as I press the keys? public class Terminos { private LeftTermin ter; private String[] commands = { "UP", "DOWN", "RIGHT", "LEFT" }; public Terminos() { initComp(); } public void initComp