Different position of a variable ......

Hi ,
I have developed a very simple program ... entering in the world of making windows , frames , gui in other words.
The first version of it:
import javax.swing.JFrame;
public class TryWindow
    static JFrame aWindow = new JFrame("This is the Window Title");
    public static void main(String[] args)
    int windowWidth = 400; // Window width in pixels
    int windowHeight = 150; // Window height in pixels
    aWindow.setBounds(50, 100 ,windowWidth, windowHeight);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setVisible(true);
   }If i leave out the word "static" then the following errors occur:
TryWindow.java:32: non-static variable aWindow cannot be referenced from a static context
    aWindow.setBounds(50, 100 ,windowWidth, windowHeight);
    ^
TryWindow.java:33: non-static variable aWindow cannot be referenced from a static context
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ^
TryWindow.java:34: non-static variable aWindow cannot be referenced from a static context
    aWindow.setVisible(true);
    ^
3 errors I have a question on this:
Which is the static context...????? The method "setDefaultCloseOperation"...???? However , the signature of this method is : public void setDefaultCloseOperation(int operation)
If i alter the position of this variable.....
2nd version
import javax.swing.JFrame;
public class TryWindow
    public static void main(String[] args)
    int windowWidth = 400; // Window width in pixels
    int windowHeight = 150; // Window height in pixels
    JFrame aWindow = new JFrame("This is the Window Title");
    aWindow.setBounds(50, 100 ,windowWidth, windowHeight);
    aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    aWindow.setVisible(true);
   }There is no problem... but there would be if i added the word "static" before the declaration of the variable....
Can you please explain why just a modification of this variable's position makes this...????
Thanks....
Sim

You are moving the variable to a static context. That is why it works.
Example:
public class StaticTest {
  //Defined public for ease of showing what I mean
  public static JFrame staticFrame = new JFrame("Static Frame");
  public JFrame nonStaticFrame = new JFrame("Non Static Frame");
  public static void main(String[] args) {
    //You are in a static function, so you can't call variables that aren't instantiated.
    //So you can't access nonStaticFrame
    staticFrame.setVisible(true); //works, your accessing this static variable from a static context.
    nonStaticFrame.setVisible(true); //ERROR Non static variable from static context!
    StaticTest test = new StaticTest();
    test.nonStaticFrame.setVisible(true); //Works since you instantiated an object that holds your nonStaticFrame.
}Edited by: hms on Jan 16, 2008 3:59 PM

Similar Messages

  • How to display the header data on different position in alv report

    hi all,
    how to display the header data on different position in alv report.
    for example ,
    customer                                                   name
      xxxx                                                         xxxx
                     vendor        name     street 
                      xxxx         xxxx      xxxxx
    pls   help me .

    hi
    as per my understanding you need to trnasfer header internal table data  to pdf..
    please check the following links for internal table to pdf..
    Convertion of Internal table data to PDF
    This link is related to ur issue
    Re: how to insert the calling of the FM: OTF to PDF
    Thanks

  • When duplicating a field, even when the original field is locked, the duplicated fields appear at different positions on pages that are the same size. How do I make them uniform?

    I'm trying to put a hidden time stamp field on the bottom of all pages of a thousand page document, yet when I duplicate the field, the reproduced fields appear at different positions on different pages. Is there a way to make them all appear uniformly on each page. I've tried using the Lock function in the Properties menu before duplicating but to no avail. Please help.

    I go to Tools>Forms> Edit...Do you want to detect...No. Add New Field>Text Field. I lay out my field at the bottom of the page, adjust the Properties (Hidden but printable, read only, font, alignment), Lock the Properties. Then I right-click and hit Duplicate.

  • Need help with Different approaches to setting variables in a Flash movie in Adobe Flash CS3 Professional Version

    Hi,
    I'm using Adobe Flash CS3 Professional version of Flash
    software,
    I need help and guidance on
    Different approaches to setting variables in a Flash movie,
    what I should do in the fla file, and in the html file.
    Thanks, Gil

    Hi petro_jemes,
    Just a little claritification, you need to add the value to the variable "[string]$ou", and also change the language in the variable "$emailbody" in the function "Get-ADUserPasswordExpirationDate".
    I hope this helps.

  • Why can I not drag a photo into a different position, In a "smart album"?

    Why can I not drag a photo into a different position, In a "smart album"?

    These are the only sort options for Smart Albums:
    OT

  • Prob. Objects with same x,y,z coordinates appear at different positions

    Hello,
    I am having a problem where I have multiple objects with the same x,y,z coordinates but they appear at different positions on the screen. Could this have anything to do with scaling as I scale different types of objects differently. Also, I am using the simple Universe class and the objects that have the problem are added to the Universe when the program is running.
    CB

    I have encoutered this problem in two occaisions. I have ships that fire bullets. When the bullets are created they are not in the same position as the ship that fired them even though they have the same translation vector.
    Here is the constructor for the Bullet--------------------------------
    The transform3D passed in is the transform3D from the ship------------
    public Bullet(Transform3D temp3d, BoundingSphere bounds) {
         // Create the root of the branch graph
         root = new BranchGroup();
    // Create a Transformgroup to scale
    tScale = new TransformGroup();
    tempTrans = new Transform3D();
    tempTrans.setScale(0.2);
    tScale.setTransform(tempTrans);
         //create the main transform and attach the shape
    transRoot = new TransformGroup();
    transRoot.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
         transRoot.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
         transRoot.addChild(new ColorCube(0.4));
    trans3d = new Transform3D(temp3d);
    transRoot.setTransform(trans3d);
         //setup behaviour
    BulletBehaviour myBehavior = new BulletBehaviour(transRoot, trans3d);
    myBehavior.setSchedulingBounds(bounds);
    transRoot.addChild(myBehavior);
         // Connect up graph
         tScale.addChild(transRoot);
         root.addChild(tScale);
         //root.addChild(transRoot);
    root.compile();
    } // end of Cube (constructor)
    The other occaision when I find this problem is when comparing the position of two objects a target and a ship.
    Check out this web page for pictures and debuging output.
    http://www.sfu.ca/~ceden/java3d/snapshots.htm

  • What are different ways to pass variables in a c# program?

    What are different ways to pass variables in a c# program?
    I was wondering if :
    var numbers = textBox1.Text.Split('
    .Select(int.Parse).ToArray();
    var min = numbers.Min();
    var max = numbers.Max();
    textBox2.Text = string.Format("min:
    {0} max: {1}", min, max);
    and
    private
    int[] numbers =
    new
    int[10];
     were considered passing variables and I am also interested in learning new ways.

    Hi Billst3r,
    Your examples would be considered creating variables or "instantiating" them, which basically means creating them in memory.  To pass variables, here is a brief example.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ConsoleApplication1
    class Program
    static void Main(string[] args)
    // Declaring variables
    int num1 = 1;
    int num2 = 5;
    // Pass created variables to private method
    int answer1 = ComputeSum(num1, num2);
    // Print results
    Console.WriteLine(answer1);
    Console.ReadLine();
    private static int ComputeSum(int param1, int param2)
    // Return sum of 2 provided parameters
    return (param1 + param2);
    Best of luck.

  • Why does images in preview are in a different position and resolution than in design view? In design view I have to place the images of screen to fit in preview.

    Why does images in preview are in a different position and resolution than in design view? In design view I have to place the images of screen to fit in preview.

    Already changed in different settings. Here is a screenshot when set to "Original Size".

  • Satellite P300: cursor jumps to different positions while typing

    Hi All,
    i have a Satellite P300,
    I am having trouble when i type.
    When i am typing using the keyboard, the first couple of words are ok, but then the words start typing in the wrong place, eg back further into the middle of the sentence i am typing.
    Anybody please help? thanks

    Hi dude
    I had a similar issue.
    While typing the cursor jumped to different positions and I was not able to finish one sentence.
    I though there could be something wrong with the keyboard but finally I have notices that I have touched the touchpad surface accidentally while typing ?.
    I have disabled the touchpad using the Fn+F9 and the issues has gone
    So maybe its the same reason for you

  • The type of the value being assigned to variable ... differs from the current variable type

    I am trying to load a variable on SSIS Execute SQL Task with a string value. I keep on getting an error message :-
    “The type of the value being assigned to variable “User::LegacyColumns” differs from the current variable type”.
    Below are the settings on my package:
    Execute SQL Task Result Set –
    Single Row
    Variable Data Type –
    String
    The data to be loaded on the variable is a single row shown below:
    FirstName,LastName,MiddleName,PatientType,Title
    Can someone kindly help me to solve this as I’m lost for ideas.
    Thanks,
    Mpumelelo

    Thank you Sorna. I think I have managed to solve it. After a long search I have found a solution which advises that I should use a Foreach Loop Container. The help is on this link:
    https://social.msdn.microsoft.com/Forums/en-US/f46dea91-c26b-4ffe-ab1c-ebeef57c90b6/error-0xc001f009-at-mypackage-the-type-of-the-value-being-assigned-to-variable?forum=sqlintegrationservices
    Mpumelelo

  • How to select different Querys based on Variable Value

    Hi guys i need to know how to select different Querys, based on variable values selected by the user, i try to do it using a Web Template but i don´t know how to program a Dynamic Query.....
    I hope sombody could help me with this
    Message was edited by: Oscar Diaz

    Hi Diaz,
    Can you explain the exact scenario which you are looking for!!!
    regards
    Happy Tony

  • Question about playlist content moving to different positions on the LCD Monitor

    Hello Experts,
    I'm trying to find out if there is a way to have the content move to different positions on the LCD Monitor.  The presentation we have always has the contenrt in the same position on the screen.  Other than creating multiple playlist and scheduliung them to play at different times I'm not sure how this can be done.  But if anyone knows how this can be accomplshed please let me know.
    Thank you ,
    Ben
    ISC Inc.

    Ah! Found it.

  • DAQ assistant different positions

    Hello
    In my VI i want to get some Signal of a PCI 6221 37 DAQ Card. I read in 2 signal which i need in different states of my application. therefore i tried to get the signals with 2 daq assistans which read date from the same card. but if i run the vi i get an error.
    How can a get my data from the same card from different positions in my block-diagramm?
    thanks
    Simon
    Using Labview 7.1

    You should just have both channels in a single DAQ Assistant. You can then use the Split Signals function.

  • How can I go to different positions within the video

    Hi,
      I need to be able to play a video at different positions within the video.  Can someone tell me how I can do this?

    in case you using a netstream object you can call:
    ns.play(startinms);

  • My macbook pro screen is totally messed up in different positions with the screen

    My screen is totally messed up when I put my screen in different positions.
    Does anyone know about this problem?
    Picture on the screen is just below.
    How am I suppose to fix this problem? I have never dropped or damaged my Macbook Pro, its in perfect conditions (besides this).
    Its a Macbook Pro 13" Sent 2011
    2,4 GHz Intel Core i5
    16 gb 1333 mhz DDR3
    Intel HD Graphics 3000 512 MB
    Thanks for the help in advance.

    Parts fail - there's likely nothing that you did to make the machine fail. Good thing you've that homeowner's insurance - I have an accidental damage rider on my renter's insurance. Something like $6 a month for up to $10,000 in coverage.
    Get the to an Apple Store or AASP... they'll be able to fix it.
    Good luck,
    Clinton

Maybe you are looking for

  • Installation of J2EE Adapter Engine with DB on different host

    Hello all, I don't know if this is the right thread, but hopefully it is. I have got following assignment: I have to install NW70 PI/XI J2EE Adapter Engine. The trouble is, that due to a CI and DB hosts politics it's necessary to have database on dif

  • Itunes stores purchase causes itunes freezes

    Despite having downloaded the latest version of Itunes (10.6), itunes freezes any time i try to buy a song.  the purchase does not complete and utines freezes until i reboot. 

  • Formatting XML into VARCHAR2

    Hi, I am looking at an XML file/feed, and within it there are paragraphs and page breaks (<para>, ). When I'm extracting the data into a varchar2 field, i want to preserve the paragraph/break structure... e.g. SELECT   text_col FROM     XMLTABLE('/'

  • How to move mail settings to a different hard drive

    My OS 10.4.11 startup hard drive was corrupted by the most recent automatic software update (either iTunes or a security update.) I figured out how to boot up from a different hard drive that had OS 10.4.8 on it. But when I access Mail, it has settin

  • EBKN-PS_PSP_PNR proviede in BI as posid

    Hi, I created a view of eban and ekbn in the sourcesystem (I didn't find something in the content). But I have the problem, that I get WBS-element only as a numeric field in BI (comes from EBKN-PS_PSP_PNR)  for example 00010487 not like I need it for