Using JFrame In Java?

Apr 16, 2014

how to use JFrames and button and so on in Java. I found this video on youtube and followed it along, however even though my program is virtually identical to his, I'm still getting errors.

Here's the video I was watching: Video

And here's my code:

import javax.swing.*; //Imports JFrame and JButton for use
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.*;
import java.awt.*;
import java.awt.event.*;
public class swing

[code]....

The reason why I'm importing some many things is I'm trying everything to try fix my problem.

He's the error messages I'm getting:

frame2.add(panel);
^
C:UsersWindows 8Documentsswing.java:42: error: illegal start of expression
frame2.add(panel);

[code]....

I used to make the button just create another frame without additional labels but I changed it to be even more similar to his program just to rule everything out. Also initially my program varied quite a bit, I've changed everything to be like his. Even without the ";" error I got, I kept telling me I was not allowed have my class as static, even though the guy in the video has it set to static. Also I don't think my "setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);" is working as it doesn't change color.

I think the problem is with my panel, it isn't adding to the frame for some reason.I'm using TextPad7 and I'm using Win8.

C:UsersWindows 8Documentsswing.java:42: error: '(' or '[' expected
frame2.add(panel);
^
C:UsersWindows 8Documentsswing.java:42: error: illegal start of expression
frame2.add(panel);

[code]....

I would also like to point out that some of the comments are out of date and are referencing the way the program was before I made it just like his. For example I know my second class isn't inheriting the first class.

View Replies


ADVERTISEMENT

Constructor Jframe In Class Jframe Not Be Applied To Types

Jun 22, 2014

So I have this line of code...

ioexception11.addChoosableFileFilter(new Jframe());

And when I compile it gives me...

error: constructor Jframe in class Jframe cannot be applied to given types;
ioexception11.addChoosableFileFilter(new Jframe());

View Replies View Related

Set Background Color Of JFrame In Java

Jul 6, 2014

how can we set the background colour of jframe in java

View Replies View Related

Swing/AWT/SWT :: Communication Between JFrame And Java Class?

Apr 19, 2014

I have a jFrame and a Java Class. Now i have a path of image in my jFrame which I want to display in java class(Crop2). I created an object in jFrame

Crop2 d=new Crop2();

and then I'm trying to send the data to the class file but it is not working.

View Replies View Related

Pass Variable In Java From One Class / Jframe To Another

Apr 3, 2015

Right so I have my ItemsPage Jframe Class and I'm trying to pass my TotalPrice variable to my CashPay so I can calculate the change. CashPrice runs and works but when I try run ItemsPage it does nothing I don't even get errors. I tried to remove that small section of trying to pass the variable to CashPay and it worked perfectly so I 100% know that's the problem. This section "public ItemsPage() { Pounds = ""; //super();

Scanner sc = new Scanner(System.in);
CashPay sendTotalPrice = new CashPay();
//System.out.println("Enter your amount");
TotalPrice = sc.nextDouble();
sendTotalPrice.printTotalPrice(TotalPrice);
"
Here is complete code for both classes, I'm using GUI builder.

import java.awt.BorderLayout;
import java.awt.Checkbox;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;

[code].....

View Replies View Related

Swing/AWT/SWT :: What Makes Java Wait On JFrame

Mar 8, 2014

With a simple "Hello World" application, once the println is executed the application exits and the process goes away.

If a simple Frame application is executed, the Frame is displayed, the println is executed but the application does not exit.

public class Frame3 extends JFrame
{
Frame3() {
setBounds(100,100,300,100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String args[]) {
new Frame3();
System.out.println("You are here");
}
}

It isn't that Java is aware an object exists because if I create a basic non-swing, non-gui object it will exit right after the println.

Q1. What is it that causes Java NOT to exit after creating the JFrame?
Q2. What type of object(s) when created will cause the application to continue running?
Q3. What would I do if I wanted the println statement to be executed only after the JFrame was closed?

View Replies View Related

Swing/AWT/SWT :: Getting JFrame Reference Into Java Bean Using RMI?

May 21, 2014

I got a project at my university , and we are working with JBoss with the free version WildFly .And also with Java EE.

Now the application is a simple game of Battle Ships or sinking ships to be honest i am not sure as to how the game is actually called.

Registering a user and saving his or her information is not hard using a Stateless java bean , to save the data in the database.

I have a Stateful java bean for every user , the bean is created on the server side after the user succeeds in logging in to the game.

This bean is used mainly for sending an invite from one user to another , to log out the user and everything else that is needed for the user.

The main problem that i encountered here is that JBoss dose not let me have a reference on my frame inside of the bean.

This makes things hard because i would need to use a Timer to ask the bean every second or so if there is an invite from someone , and i would need to save all of the invites .

This was the only thing i could think of .And also implementing the game it self , the communication between users would be complicated more so than i think its needed.

Then my professor said that i could make a service on the clients side in witch i would have a reference of the JFrame , and i could send this service to the java bean and using this service i could get access to the JFrame making things faster.

This would make things a lot easier.For the invite and for the game itself too.

My professor explained that JBoss or WildFly is based on RMI , and he said also that i would need to set up the registry on the server side .But i got lost because i was not sure as to what should i search for .

We are using an older version of WildFly not the newest but one version older , CR1 i think.

And we are also using JPA in the Dynamic web project , server .

View Replies View Related

Swing/AWT/SWT :: How To Print JFrame Content Using NetBeans Java

Sep 10, 2014

I am developing a program in netbeans forms. I've got to a point where I will click a jButton to print the content of either JFrame or JPanel. I am using Netbeans forms to develop the project....

View Replies View Related

Java - Getting Data RFID Serial Rs232 In JFrame Class

Apr 14, 2014

**Getting data on from rfid scanner as Serial rs232 port in JFrame**, in this case I have made a JFrame form and I have a JTextField for storing data rfid as a String. Actually, I found a class from internet that read the RFID reader as byte, now How To get data from my RFID Class to my JTextfield Jframe in my main class as String?

Here my RFID class :

package view;
import java.util.*;
import java.io.*;
import javax.comm.*;
public class ListPorts implements Runnable, SerialPortEventListener {
static CommPortIdentifier portId;
static Enumeration portList;

[Code] ....

Is it possible that my RFID class merge with my Main class ?

View Replies View Related

Call A JFrame From Another JFrame?

Jan 23, 2015

how we call a jFrame from another jFrame .

View Replies View Related

Cannot Get JFrame To Run And Pop Up

Apr 24, 2014

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tables;
import java.util.Date;
import javax.swing.table.DefaultTableModel;
import javax.swing.JOptionPane;
import javax.swing.RowFilter;
import javax.swing.table.TableRowSorter;

[Code]...

Iam using J grasp or text wrangler for macbook

View Replies View Related

Displaying MP4 Within JFrame?

Apr 5, 2015

I was wondering if its possible to show a video (mp4) inside a jframe? like the windows media player ....

View Replies View Related

How To Build GUI With JFrame

Nov 10, 2014

how to build GUI's with JFrame and I was firstly very confused as to when and what is always needed for any GUI in Java. How do I know everything I need for a GUI? Are there certain things every GUI will need by default?

Additionally below I have a code snippet of when this person used the "this" as an argument to a JButton and Im just really confused for when I can use it and when I can't.

public UIStuff(){
super("Multiple Button Events");
init();
} // end multi-button
 
[code]....

View Replies View Related

Add A Website Into One Of JFrame?

Feb 3, 2014

im working on a program, but i have question and its. How can i add a website into one of my "JFrame" i have made?

exampel i want to add google.com website into the fram called V2.

HERE IS MY CODE:

Java Code: package mittprogram;
import java.awt.Color;
import java.awt.Font;

[Code].....

View Replies View Related

Calling One Jframe From Another 2

Apr 23, 2014

i am creating a desktop application. In this application, firstly there is a log in form. Now, i want to display the another form on the same window i.e by removing log in form a new form..

View Replies View Related

JFrame - ImageIcon Not Displaying?

Apr 14, 2014

why my image may not be showing. Note I am using eclipse.

Window.java:

import javax.swing.*;
 public class Window {
private JFrame gameWindow;
 public Window() {
gameWindow = new JFrame("Tamagotchi!");

[code]....

I have used file.exists() and this returns true, and file.length() which returns the correct file size.

System.out.println(backgroundImage) returns "splash.png" so thats ok.

Why then is my image not showing?

View Replies View Related

JFrame - Gathering Info From Net?

Nov 7, 2014

I'd like to know how to,

1. Connect to Google,
2. Search for something,
3. Return a SCREEN SHOT of the results.

I'm assuming this involves loading the webpage into a JFrame, or is there an easy workaround?

View Replies View Related

Rectangle Won't Display In JFrame

Jan 30, 2014

So I've been getting back into Java and downloaded eclipse back onto my laptop. However when I go to make a simple rectangle into a JFrame, the frame will pop up but no rectangle will be shown. Here is my main class, which sets up the JFrame...

mport javax.swing.JFrame;
public class Frame{
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setTitle("I hope this fucking works");
frame.setSize(400,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

[code]....

View Replies View Related

Swing/AWT/SWT :: Add A Rectangle To JFrame?

Apr 13, 2014

Is there a way to simply slap a rectangle into a JPanel (make it appear) with out creating an inner Class or helper Method, all within "Main"? And if not, why?

Making a JFrame is easy.

Adding a JPanel is a snap.

import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TheJFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub

[code]....

View Replies View Related

Inserting Image In JFrame

Feb 3, 2014

I want to insert an image in a jframe...

View Replies View Related

Rectangle Isn't Showing Up In JFrame

Nov 14, 2014

MyGraphics worked before I added a background but, even now when I take the background away it isn't showing up.

package com.snow.game;
import javax.swing.*;
import java.awt.*;
class MyGraphics extends JComponent { //creating a class for graphics
public void draw(Graphics g){
//calling Graphics making a new graphics (g) now you can use it to make objects
g.drawRect(10, 10, 50, 50); //Draws a rectangle

[Code] ......

View Replies View Related

Unable To Hide Jframe

Apr 4, 2015

Tried it, I get red line under it, tried to do "jframe1 jframe1 = new jframe1(variable);

jframe1.setVisible(False); still failed. all I want to do is open a different jframe which I got that to work but cant hide show me how to do it without having to emend my code I want to be able to do is in same style.

CashPaybtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
//System.out.println("CashPaybtn.actionPerformed, event="+evt);
//TODO add your code for CashPaybtn.actionPerformed
//PaymentMethod.setVisible(false);

[Code]...

View Replies View Related

How To Manage JFrame In JCreator

Dec 2, 2014

how to manage JFrame in JCreator .

View Replies View Related

How To Get Image To Display On JFrame

Nov 13, 2014

I have been trying to make a game lately, but I can't seem to work out how to get an image to display on my JFrame. I have tried everything, copied different codes of the internet, but nothing works. Here is my code of the GUI:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GUI extends JFrame implements Runnable, ActionListener {
JButton start = new JButton("Start nieuw spel");
JButton instellingen = new JButton("Instellingen");
public GUI() {

[Code]...

View Replies View Related

How To Print JFrame With All Its Subcomponents

Oct 5, 2014

I have a form in netbeans java. I want to print the form as it is.Actually I want to print the bill. I am beginner in netbeans java.

View Replies View Related

How To Get Time Shown In JFrame

Aug 8, 2014

I am trying to to insert time onto my jFrame (Netbeans) by using textfields. this is the code i've tried to put into the textfield so whenever i run the program it automatically shows the time.

Calendar now = Calendar.getInstance();
hours = now.get(Calendar.HOUR);
minutes = now.get(Calendar.MINUTE);
seconds = now.get(Calendar.SECOND);
millis = now.get(Calendar.MILLISECOND);

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved