jframe

Adding jlabel to a jframe using components

时光怂恿深爱的人放手 提交于 2019-12-02 14:51:29
I have 2 classes, My main class creates a frame and I want another class to add content to it. A bit of reading arroudn told me I should use components to do this however when I run my code the frame is empty. public static void main(String[] args) { // create frame JFrame frame = new JFrame(); final int FRAME_WIDTH = 800; final int FRAME_HEIGHT = 600; // set frame attributes frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); frame.setTitle("My Frame"); frame.setVisible(true); Component1 Com = new Component1(); Component add = frame.add(Com); } My Component class creates a JLabel public class

How to save a image on JFrame

那年仲夏 提交于 2019-12-02 14:37:54
问题 I am working on a white board project and I encountered a problem when implementing the Save function. Here is how I implement the draw function Graphics2D g2d = (Graphics2D) frm.getGraphics(); g2d.setColor(Current_Color); Line2D p2d = new Line2D.Double(StartPoint.getX(),StartPoint.getY(), e.getX() + Xoffset, e.getY() + Yoffset); g2d.setStroke(new BasicStroke(Integer.parseInt(choice_size.getSelectedItem()))); g2d.draw(p2d); I am using JFileChooser for the file dialog int returnVal =

Switching between JPanels in a JFrame

只谈情不闲聊 提交于 2019-12-02 13:55:45
问题 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 =

My jframe doesn't shows [closed]

那年仲夏 提交于 2019-12-02 13:43:37
I'm beginner woth java programming I tried to make my jframe shows but it didn't jframe.setVisible(true); it doesn't works I think you didn't declare correctly your JFrame. Here is an example creating a simple frame : public static void main(String[] args) { // Creating a frame JFrame frame = new JFrame("Example"); // Setting the position and the size of the frame frame.setBounds(0,0,800,600); // This will terminate the program when closing the frame frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Then you can display your frame frame.setVisible(true); } 来源: https://stackoverflow.com

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

拥有回忆 提交于 2019-12-02 13:38:18
问题 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

Error with timer and JFrame

半城伤御伤魂 提交于 2019-12-02 13:32:11
I'm making a game with a timer and a JFrame (and many other things but only these 2 are causing problems), and after running the segments below, I got a weird error. At least for me who has never used these classes prior to this. Start executing this private static GameView window; private static Timer time; public static void main(String args[]) { window = new GameView(800,600); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setVisible(true); time = new Timer(); time.schedule( new TimerTask(){ public void run(){GameState.update(); window.paintComponents(null);} },0, 40); }

Setting fullscreen using other ways besides getting screen size in Java

别来无恙 提交于 2019-12-02 13:27:37
I was wondering if there was a way that is better than using the Toolkit.getDefaultToolkit().getScreenSize().getHeight()/getWidth(); and then using that as the dimensions for the JFrame and then setting the JFrame to undecorated ? Would there be some sort of pre-built function in Java that takes control of the graphics card for a true fullscreen? You're after what's called "full-screen exclusive mode" Have a look at Full-Screen Exclusive Mode for more details. Understand though, it doesn't play well with Swing. Under Mac OS X 10.7, you can access the full screen support it provides for

Switch two panels in on

筅森魡賤 提交于 2019-12-02 13:19:32
I have got one J Frame that includes 2 panels , I was able to switch between them using Visible but I want them to appear in the same position and the same size the other was in. Use a CardLayout to swap JPanels. The tutorial can be found here: CardLayout tutorial . When you do this, you will need a JPanel to be set to use the CardLayout and which will hold your other two JPanels. You will need to add these JPanels to the CardLayout using JPanel with String constants, so that the CardLayout will be able to identify the views with a String. For instance: CardLayout cardLayout = new CardLayout()

Setting up KeyListeners using the MVC in java

天涯浪子 提交于 2019-12-02 13:15:05
问题 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

JFrame Glasspane is also over JDialog but shouldn't

假如想象 提交于 2019-12-02 13:13:28
I have a JFrame (undecorated) with a Glasspane. This Frame opens a JDialog (also undecorated and has also a glassPane) and hides itself (setVisible(false)). The Glasspanes are set with .setGlassPane(). The Dialog is opened with the Frame as owner. The GlassPane extends a JPanel and implements AWTEventListener. I use it for resizing the Frames and Dialogs, so it knows it's parent (the Frame/Dialog) - this is called "target". The Events inside the GlassPane are handled like this: public void eventDispatched(AWTEvent event) { if (target instanceof JFrame) { e = SwingUtilities.convertMouseEvent( (