Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2, JDK 5 Edition
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 25th, 2011, 10:39 PM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Possible version issues?

Hi, I just started getting into Java, and got through the book to Chapter 17 before I had access to the source code and other downloads.

On my Mac 10.6.6 with java version "1.6.0_22"
Java(TM) SE Runtime Environment (build 1.6.0_22-b04-307-10M3261)
Java HotSpot(TM) 64-Bit Server VM (build 17.1-b03-307, mixed mode)

I tried to copy an example program from Chapter 17, the


package tryboxlayout;

import java.awt.Toolkit;
import java.awt.Dimension;
import java.awt.Container;
import java.awt.BorderLayout;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.BoxLayout;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.BorderFactory;
import javax.swing.border.Border;

public class TryBoxLayout {
// The window object
static JFrame aWindow = new JFrame("This is a Box Layout");

public static void main(String[] args) {
Toolkit theKit = aWindow.getToolkit(); // Get the window toolkit
Dimension wndSize = theKit.getScreenSize(); // Get screen size

// Set the position to screen center & size to half screen size
aWindow.setBounds(wndSize.width/4, wndSize.height/4, // Position
wndSize.width/2, wndSize.height/2); // Size
aWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CL OSE);

// Create left column of radio buttons
Box left = Box.createVerticalBox();
ButtonGroup radioGroup = new ButtonGroup(); // Create button group
JRadioButton rbutton; // Stores a button
radioGroup.add(rbutton = new JRadioButton("Red")); // Add to group
left.add(rbutton); // Add to Box
radioGroup.add(rbutton = new JRadioButton("Green"));
left.add(rbutton);
radioGroup.add(rbutton = new JRadioButton("Blue"));
left.add(rbutton);
radioGroup.add(rbutton = new JRadioButton("Yellow"));
left.add(rbutton);

// Create right columns of checkboxes
Box right = Box.createVerticalBox();
right.add(new JCheckBox("Dashed"));
right.add(new JCheckBox("Thick"));
right.add(new JCheckBox("Rounded"));

// Create top row to hold left and right
Box top = Box.createHorizontalBox();
top.add(left);
top.add(right);
// Create bottom row of buttons
JPanel bottomPanel = new JPanel();
Border edge = BorderFactory.createRaisedBevelBorder(); // Button border
JButton button;
Dimension size = new Dimension(80,20);
bottomPanel.add(button = new JButton("Defaults"));
button.setBorder(edge);
button.setPreferredSize(size);
bottomPanel.add(button = new JButton("OK"));
button.setBorder(edge);
button.setPreferredSize(size);
bottomPanel.add(button = new JButton("Cancel"));
button.setBorder(edge);
button.setPreferredSize(size);

// Add top and bottom panel to content pane
Container content = aWindow.getContentPane(); // Get content pane
content.setLayout(new BorderLayout()); // Set border layout manager
content.add(top, BorderLayout.CENTER);
content.add(bottomPanel, BorderLayout.SOUTH);
aWindow.pack();
aWindow.setVisible(true); // Display the window
}
}

And it will not run. In Netbeans it will build successfully, but no pop up window. If I compile it for cmdln, I call it as java -jar and get no return.

Is this going to be a further issue, is there something I can do to correct it?

Thanks.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Where can I get the 1.5 Version??? danielc1 BOOK: Professional Microsoft Robotics Studio ISBN: 978-0-470-14107-6 1 July 18th, 2009 05:01 AM
Version issues Spider ASP.NET 3.5 Basics 3 March 2nd, 2009 03:00 PM
connection string issues, web.config file issues kaliaparijat ASP.NET 2.0 Professional 1 June 12th, 2008 09:07 AM
Passwords from version 1 to version 2 Maxxim BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 February 6th, 2007 06:49 PM



All times are GMT -4. The time now is 05:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.