Page 2 of 2 FirstFirst 12
Results 21 to 33 of 33
  1. #21
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    i wanna create 300x300 window

    Java Code:
    	public void MakeMap() {
    		JFrame frame = new JFrame("Test");
    		JPanel panel = new JPanel(new GridLayout(1,1));
    		frame.setSize(300,300);
    		frame.getContentPane().add(panel);
    		frame.pack();
    		frame.show();
    	}
    the window isnt 300,300 when i run it . what may be the problem

  2. #22
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Char View Post
    i wanna create 300x300 window

    Java Code:
    	public void MakeMap() {
    		JFrame frame = new JFrame("Test");
    		JPanel panel = new JPanel(new GridLayout(1,1));
    		frame.setSize(300,300);
    		frame.getContentPane().add(panel);
    		frame.pack();
    		frame.show();
    	}
    the window isnt 300,300 when i run it . what may be the problem
    Don't pack() your frame.

    kind regards,

    Jos

  3. #23
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Don't pack() your frame.

    kind regards,

    Jos
    thanks Jos, heres 2 more questions

    1)
    PACK Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.

    so when i would

    Java Code:
    	public void MakeMap() {
    		JFrame frame = new JFrame("Test");
    		JPanel panel = new JPanel(new GridLayout(1,1));
    		panel.setSize(300,300);
    		frame.getContentPane().add(panel);
    		frame.pack();
    		frame.show();
    	}
    why its not 300x300
    it should take size of its subcomponent, such as the jpanel

    2)

    what i discovere that when i add this line, my window is exactly in the middle of screen..why is that? what is meant under "this"?

    Java Code:
    frame.setLocationRelativeTo(this);
    Last edited by Char; 08-13-2010 at 03:33 PM.

  4. #24
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,375
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Char View Post
    thanks Jos, heres 2 more questions

    1)
    PACK Causes this Window to be sized to fit the preferred size and layouts of its subcomponents.

    so when i would

    Java Code:
    	public void MakeMap() {
    		JFrame frame = new JFrame("Test");
    		JPanel panel = new JPanel(new GridLayout(1,1));
    		panel.setSize(300,300);
    		frame.getContentPane().add(panel);
    		frame.pack();
    		frame.show();
    	}
    why its not 300x300
    it should take size of its subcomponent, such as the jpanel
    You haven't set the preferred size of the JPanel.

    2)

    what i discovere that when i add this line, my window is exactly in the middle of screen..why is that? what is meant under "this"?

    Java Code:
    frame.setLocationRelativeTo(this);
    I don't know because you haven't told us in which class (object) you have that line of code.

    kind regards,

    Jos

  5. #25
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    Java Code:
    import java.awt.Dimension;
    import java.awt.GridLayout;
    
    import javax.swing.*;
    
    
    public class Map extends JFrame {
    	public void MakeMap() {
    		JFrame frame = new JFrame("Test");
    		JPanel panel = new JPanel(new GridLayout(21,21));
    		frame.setSize(588,588); // 21 x 28 boxes
    		frame.setLocationRelativeTo(this);
    		frame.getContentPane().add(panel);
    		frame.setVisible(true);
    	}
    }

    2) also lets say i have a shortcut on the desktop , how can i open it with java ? just to run it
    Last edited by Char; 08-13-2010 at 04:26 PM.

  6. #26
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    i have a shortcut on the desktop , how can i open it with java ? just to run it
    What does the shortcut point to? What does it execute when you double click it?
    What is in the target field of the shortcut's Properties?

    What do the two "it"s in the above quote refer to?

  7. #27
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    Java Code:
    	public void MakeMap() {
    		JFrame frame = new JFrame("Test"); // makes  jframe
    		JPanel panel = new JPanel(new GridLayout(1,1)); // makes jpanel
    		panel.setSize(300,300); // makes panel size 300,300
    		frame.getContentPane().add(panel); // adds panel to frame
    		frame.pack(); // changes size of frame to the size of its subcontent(panel) , so frame should have size 300,300
    		frame.setVisible(true); // makes it visible
    	}
    i also added comments for lines, how i understand the code
    it -> window

    well actually its not a shortcut, its a mp3 file heh
    Last edited by Char; 08-13-2010 at 06:12 PM.

  8. #28
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    i have a shortcut on the desktop , how can i open window with java ? just to run window

    Don't understand what you were asking if 'it' referred to window.

  9. #29
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    i have a shortcut on the desktop , how can i open window with java ? just to run window

    Don't understand what you were asking if 'it' referred to window.
    it -> shortcut

    and its actually an mp3 file , not shortcut, sorry

  10. #30
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    okay ive got 1 problems now where im stuck

    1) i want my program to press ~ key

    what i found is this, but it isnt working
    Java Code:
    robot.keyPress(KeyEvent.VK_DEAD_TILDE);
    error i get :

    Java Code:
    Exception in thread "main" java.lang.IllegalArgumentException: Invalid key code
    	at sun.awt.windows.WRobotPeer.keyPress(Native Method)
    	at java.awt.Robot.keyPress(Unknown Source)
    	at Counter.main(Counter.java:9)
    2) i have mp3 file in location C:\Users\Music\test.mp3 and i want to open the mp3

  11. #31
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Please start a new thread for a new topic.

  12. #32
    Char's Avatar
    Char is offline Member
    Join Date
    Dec 2009
    Posts
    41
    Rep Power
    0

    Default

    really new thread for new question? ive got so many questions,i don't want to spam this site..that's why i thought id make my own thread ?!

  13. #33
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You're not spamming when you ask a Java-related question, and the general etiquette is for one thread per question, and for several reasons, including:

    1) Many helpers avoid questions with many responses, figuring that the question has already been well answered.
    2) Having your Thread title be a brief summary of your question increases the chance that an expert on your question subject will find your question, see that it is one they can answer, and answer it.
    3) Also folks with similar questions can find your question more easily, can study it, and can find answers that are useful to them. Please understand that your questions are not just for your benefit but also for the benefit of those who run across it in the future.

    Much luck!

Page 2 of 2 FirstFirst 12

Similar Threads

  1. questions for 1yr exp
    By rahaman.athiq in forum Java Servlet
    Replies: 2
    Last Post: 11-26-2008, 01:13 AM
  2. I have Questions -_-
    By ChazZeromus in forum New To Java
    Replies: 5
    Last Post: 09-13-2008, 08:08 PM
  3. Questions About JSP?
    By mtz1406 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 08-19-2008, 07:56 PM
  4. Just a Few Questions
    By pringle in forum New To Java
    Replies: 21
    Last Post: 01-09-2008, 06:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •