jframe

JFrame (swing) switching repeating actions with buttons

岁酱吖の 提交于 2019-12-02 05:48:39
I want a JFrame application with 2 buttons (eventually more) that I can use to switch between multiple repeating actions, ofr simplicity I'm just using a console print for now, though it will probably be calling a method instead later. Here is the framework for the JFrame: public class DayNight extends JFrame implements ActionListener{ //JFrame entities private JPanel animationPanel; private JButton button; private JButton button2; public static void main(String[] args) { DayNight frame = new DayNight(); frame.setSize(2000, 1300); frame.setLocation(1000,350); frame.createGUI(); frame

Setting up KeyListeners using the MVC in java

孤街浪徒 提交于 2019-12-02 05:29:11
I am trying to make myself a calculator in Java. I figured it would be best to implement the MVC (model view controller) design for my code. I have some of the basics working, the calculator does actually work, the issue is i cannot figure out where i am going wrong with the implementation of listening to keys. At the moment i have the ability to click on the buttons using the action listener and updating the field with a numeric value and the buttons to add, subtract, multiply, divide and also to clear. So really the only thing on my mind at the moment is trying to allow the user (myself) the

Java: Can't apply Gridlayout to a Jscrollpane. Get Get java.lang.ClassCastException

倾然丶 夕夏残阳落幕 提交于 2019-12-02 04:48:07
I use a Gridlayout to place 4 elements in one Line. First I had a JPanel and everything worked fine. For the case that the number of lines get to big and I have to be able to scroll down, I changed it a bit. Now I have my JPanel with one JScrollPane added on it. I used the same code, now I just add the elements to the viewport of the Jscrollpane , but now I get this exception Get java.lang.ClassCastException: layout of JScrollPane must be a ScrollPaneLayout: at javax.swing.JScrollPane.setLayout(Unknown Source) and I dont know exactly why. Why shouldnt be Gridlayout's be unknown for Jscrollpane

Add components directly to JFrame, or put them inside a JPanel?

梦想与她 提交于 2019-12-02 04:38:11
I have a general question regarding java GUI. If I have several components that I want to add to a JFrame, should i put them directly inside the JFrame, or add them to a JPanel, and then add the panel to the frame? If adding the components to a JPanel first is the best, why? I usually do this, then I understood that I have no idea why/if this is more optional then adding directly to the frame. JFrame also have layout managers, so it's possible to get them in the correct position. When you add components to the frame you add the components to the content pane of the frame. The content pane is a

ActionListener isn't Implementing

余生颓废 提交于 2019-12-02 04:37:40
JFrameWithPanel is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener public class JFrameWithPanel extends JFrame implements ActionListener I Don't get this code. Book and Java site tells me this is the syntax for the method, but again this error shows up constantly. import javax.swing.*; import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; import java.lang.Math.*; import java.lang.Integer.*; import java.util.*; import java.util.Random; import java.io.*; import java.text.*; import java.text

disposing frame from swingWorker

南楼画角 提交于 2019-12-02 04:35:24
actually i have called the swing worker from a frame (Suppose) A.. in the swing worker class in do-in-Background method i have certain db queries and i am calling frame B too.. in the done() method however i want to dispose the frame A.. how can i do that..? i cannot write dispose() in frame A class because that results in disposing of frame before the new frame(frame B) is visible... Please help!! class frameA extends JFrame{ public frameA(){ //done some operations.. SwingWorker worker=new Worker(); worker.execute(); } public static void main(string[] args){ new frameA(); } } and in worker

Java full screen background color wont change?

跟風遠走 提交于 2019-12-02 04:08:30
I have some code that creates a full screen icon in java and sets the background color to pink and the foreground color to red. However every time i run it, it never changes the background color to red but just keeps it see through. I put the code below. The main java: import java.awt.*; import javax.swing.*; @SuppressWarnings({ "serial" }) public class bob extends JFrame{ public static void main(String[] args) { DisplayMode dm = new DisplayMode(800,600,16, DisplayMode.REFRESH_RATE_UNKNOWN); bob b = new bob(); b.run(dm); } public void run(DisplayMode dm){ setBackground(Color.PINK);

Switching between JPanels in a JFrame

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-02 04:04:59
Now I know there are many, many questions on this and I've read a dozen. But I've just hit a wall, I can't make heads or tails of it. Heres my question. I have 3 Panel classes. ConfigurePanel.java ConnectServerPanel.java RunServerPanel.java and my JFrame class StartUPGUI.java This is what is initialised at startup private void initComponents() { jPanel1 = new javax.swing.JPanel(); startUp = new sjdproject.GUI.ConfigurePanel(); runServer = new sjdproject.GUI.RunServerPanel(); serverConnect = new sjdproject.GUI.ConnectServerPanel(); setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING

How to set the JFreeChart X axis data titles?

倾然丶 夕夏残阳落幕 提交于 2019-12-02 04:03:32
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; import org.jfree.data.xy.XYDataset; import org.jfree.data.xy.XYSeries; import org.jfree.data.xy

JPanel fills all JFrame space

人盡茶涼 提交于 2019-12-02 03:46:27
问题 I have write this code for displaying some set of colors from panel: import java.util.ArrayList; import java.util.List; import javax.swing.JFrame; import javax.swing.JPanel; public class Palette { public static void main(String[] args) { JFrame frame = new JFrame("Panel"); palette.add(new Color(255, 0, 0)); palette.add(new Color(0, 255, 0)); palette.add(new Color(0, 0, 255)); int width = 100; int height = 250; int x = 0; for (Color color : palette) { JPanel panel = new JPanel(); panel.setSize