Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Starting a Slideshow Program... Lost

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Starting a Slideshow Program... Lost

    I'm trying to get started on a slideshow program, but I'm stuck trying to print an image to the canvas I've created. Any help would be appreciated. I know its sloppy now. I'm kind of new at this. The problem seems to be between lines 321 and 338 in the getBrowseAction method.

    package tutorial.swing.jigloo;
    import java.awt.BorderLayout;
    import java.awt.Canvas;
    import java.awt.Component;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.image.BufferedImage;
    import java.awt.image.ImageObserver;
    import java.io.File;
    import java.io.IOException;
    import java.net.URL;
     
    import javax.imageio.ImageIO;
    import javax.swing.AbstractAction;
    import javax.swing.BorderFactory;
    import javax.swing.GroupLayout;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JDialog;
    import javax.swing.JFileChooser;
    import javax.swing.JLabel;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTable;
    import javax.swing.JTextField;
    import javax.swing.KeyStroke;
    import javax.swing.LayoutStyle;
    import javax.swing.SwingConstants;
     
    import javax.swing.WindowConstants;
    import javax.swing.border.LineBorder;
    import javax.swing.border.TitledBorder;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableModel;
    import javax.swing.SwingUtilities;
     
    import javax.swing.ImageIcon;
     
     
    /**
    * This code was edited or generated using CloudGarden's Jigloo
    * SWT/Swing GUI Builder, which is free for non-commercial
    * use. If Jigloo is being used commercially (ie, by a corporation,
    * company or business for any purpose whatever) then you
    * should purchase a license for each developer using Jigloo.
    * Please visit www.cloudgarden.com for details.
    * Use of Jigloo implies acceptance of these licensing terms.
    * A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
    * THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
    * LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
    */
    public class MainJFrame extends javax.swing.JFrame {
    	private JButton cancelButton;
    	private JScrollPane jScrollPane1;
    	private AbstractAction fileBrowserAction;
    	private JButton jButton4;
    	private JLabel aboutLabel;
    	private Canvas canvas1;
    	private AbstractAction browsedFileAction;
    	private AbstractAction browseAction;
    	private JFileChooser jFileChooser1;
    	private JPanel fileChooserPanel;
    	private AbstractAction okAction;
    	private JDialog jDialog2;
    	private AbstractAction aboutAction;
    	private JMenuItem jMenuItem1;
    	private JMenu helpMenu;
    	private JMenu jMenu1;
    	private JMenuBar jMenuBar1;
    	private JTextField jTextField6;
    	private JTextField jTextField5;
    	private JButton jButton3;
    	private JButton jButton1;
    	private JPanel jPanel2;
    	private JTabbedPane jTabbedPane1;
    	private JPanel jPanel1;
    	private JTextField jTextField2;
    	private JTextField jTextField1;
    	private JButton okButton;
     
    	/**
    	* Auto-generated main method to display this JFrame
    	*/
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				MainJFrame inst = new MainJFrame();
    				inst.setLocationRelativeTo(null);
    				inst.setVisible(true);
    			}
    		});
    	}
     
    	public MainJFrame() {
    		super();
    		initGUI();
    	}
     
    	private void initGUI() {
    		try {
    			GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
    			getContentPane().setLayout(thisLayout);
    			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    			{
    				jMenuBar1 = new JMenuBar();
    				setJMenuBar(jMenuBar1);
    				{
    					jMenu1 = new JMenu();
    					jMenuBar1.add(jMenu1);
    					jMenu1.setText("File");
    				}
    				{
    					helpMenu = new JMenu();
    					jMenuBar1.add(helpMenu);
    					helpMenu.setText("Help");
    					{
    						jMenuItem1 = new JMenuItem();
    						helpMenu.add(jMenuItem1);
    						jMenuItem1.setText("jMenuItem1");
    						jMenuItem1.setAction(getAboutAction());
    					}
    				}
    			}
    			{
    				cancelButton = new JButton();
    				cancelButton.setText("Cancel");
    				cancelButton.setFont(new java.awt.Font("Dialog",1,12));
    			}
    			{
    				jScrollPane1 = new JScrollPane();
    				jScrollPane1.setViewportView(getCanvas1());
    			}
    			{
    				jTabbedPane1 = new JTabbedPane();
    				{
    					jPanel1 = new JPanel();
    					jTabbedPane1.addTab("jPanel1", null, jPanel1, null);
    					GroupLayout jPanel1Layout = new GroupLayout((JComponent)jPanel1);
    					jPanel1.setLayout(jPanel1Layout);
    					jPanel1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder(""), "\"Group 1\"", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION));
    					jPanel1.setPreferredSize(new java.awt.Dimension(259, 72));
    					{
    						jTextField2 = new JTextField();
    						jTextField2.setText("jTextField2");
    					}
    					{
    						jButton1 = new JButton();
    						jButton1.setText("Browse...");
    						jButton1.setAction(getBrowseAction());
    					}
    					{
    						jTextField1 = new JTextField();
    						jTextField1.setText("jTextField1");
    						jTextField1.setAction(getBrowsedFileAction());
    					}
    					jPanel1Layout.setHorizontalGroup(jPanel1Layout.createSequentialGroup()
    						.addGroup(jPanel1Layout.createParallelGroup()
    						    .addGroup(GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
    						        .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
    						        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    						        .addComponent(jButton1, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
    						    .addGroup(jPanel1Layout.createSequentialGroup()
    						        .addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, 139, GroupLayout.PREFERRED_SIZE)))
    						.addContainerGap(12, Short.MAX_VALUE));
    					jPanel1Layout.setVerticalGroup(jPanel1Layout.createSequentialGroup()
    						.addContainerGap()
    						.addGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
    						    .addComponent(jTextField1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
    						    .addComponent(jButton1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
    						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    						.addComponent(jTextField2, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE));
    				}
    				{
    					jPanel2 = new JPanel();
    					jTabbedPane1.addTab("jPanel1", null, jPanel2, null);
    					GroupLayout jPanel2Layout = new GroupLayout((JComponent)jPanel2);
    					jPanel2.setPreferredSize(new java.awt.Dimension(150, 72));
    					jPanel2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createTitledBorder(""),"\"Group 1\"",TitledBorder.LEADING,TitledBorder.DEFAULT_POSITION));
    					jPanel2.setLayout(jPanel2Layout);
    					{
    						jButton3 = new JButton();
    						jButton3.setText("jButton1");
    					}
    					{
    						jTextField5 = new JTextField();
    						jTextField5.setText("jTextField1");
    					}
    					{
    						jTextField6 = new JTextField();
    						jTextField6.setText("jTextField2");
    					}
    				jPanel2Layout.setHorizontalGroup(jPanel2Layout.createSequentialGroup()
    						.addContainerGap(22, 22)
    						.addGroup(jPanel2Layout.createParallelGroup()
    						    .addGroup(jPanel2Layout.createSequentialGroup()
    						        .addComponent(jTextField6, GroupLayout.PREFERRED_SIZE, 139, GroupLayout.PREFERRED_SIZE))
    						    .addGroup(GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
    						        .addComponent(jTextField5, GroupLayout.PREFERRED_SIZE, 71, GroupLayout.PREFERRED_SIZE)
    						        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    						        .addComponent(jButton3, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)))
    						.addContainerGap(25, Short.MAX_VALUE));
    				jPanel2Layout.setVerticalGroup(jPanel2Layout.createSequentialGroup()
    						.addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
    						    .addComponent(jButton3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
    						    .addComponent(jTextField5, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE))
    						.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
    						.addComponent(jTextField6, GroupLayout.PREFERRED_SIZE, 22, GroupLayout.PREFERRED_SIZE)
    						.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    				}
    			}
    			{
    				okButton = new JButton();
    				okButton.setText("Ok");
    				okButton.setFont(new java.awt.Font("Dialog",1,12));
    			}
    			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
    				.addContainerGap()
    				.addComponent(jScrollPane1, 0, 98, Short.MAX_VALUE)
    				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED, 1, GroupLayout.PREFERRED_SIZE)
    				.addComponent(jTabbedPane1, GroupLayout.PREFERRED_SIZE, 207, GroupLayout.PREFERRED_SIZE)
    				.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
    				    .addComponent(okButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
    				    .addComponent(cancelButton, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE))
    				.addGap(7));
    			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
    				.addContainerGap()
    				.addGroup(thisLayout.createParallelGroup()
    				    .addComponent(jScrollPane1, GroupLayout.Alignment.LEADING, 0, 537, Short.MAX_VALUE)
    				    .addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
    				        .addPreferredGap(jScrollPane1, jTabbedPane1, LayoutStyle.ComponentPlacement.INDENT)
    				        .addComponent(jTabbedPane1, GroupLayout.PREFERRED_SIZE, 365, GroupLayout.PREFERRED_SIZE)
    				        .addGap(0, 26, Short.MAX_VALUE)
    				        .addComponent(okButton, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)
    				        .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
    				        .addComponent(cancelButton, GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)))
    				.addContainerGap());
    			thisLayout.linkSize(SwingConstants.HORIZONTAL, new Component[] {cancelButton, okButton});
    			pack();
    			this.setSize(561, 405);
    		} catch (Exception e) {
    		    //add your error handling code here
    			e.printStackTrace();
    		}
    	}
     
    	private AbstractAction getAboutAction() {
    		if(aboutAction == null) {
    			aboutAction = new AbstractAction("about", null) {
    				public void actionPerformed(ActionEvent evt) {
    					getJDialog2().pack();
    					getJDialog2().setLocationRelativeTo(null);
    					getJDialog2().setVisible(true);
    				}
    			};
    			aboutAction.putValue(javax.swing.Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("shift meta pressed A"));
    		}
    		return aboutAction;
    	}
     
    	private JDialog getJDialog2() {
    		if(jDialog2 == null) {
    			jDialog2 = new JDialog(this);
    			GroupLayout jDialog2Layout = new GroupLayout((JComponent)jDialog2.getContentPane());
    			jDialog2.setLayout(jDialog2Layout);
    			jDialog2.setSize(329, 156);
    			jDialog2Layout.setHorizontalGroup(jDialog2Layout.createSequentialGroup()
    				.addContainerGap()
    				.addGroup(jDialog2Layout.createParallelGroup()
    				    .addComponent(getAboutLabel(), GroupLayout.Alignment.LEADING, 0, 305, Short.MAX_VALUE)
    				    .addGroup(GroupLayout.Alignment.LEADING, jDialog2Layout.createSequentialGroup()
    				        .addGap(0, 243, Short.MAX_VALUE)
    				        .addComponent(getJButton4(), GroupLayout.PREFERRED_SIZE, 62, GroupLayout.PREFERRED_SIZE)))
    				.addContainerGap());
    			jDialog2Layout.setVerticalGroup(jDialog2Layout.createSequentialGroup()
    				.addContainerGap()
    				.addComponent(getAboutLabel(), GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
    				.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
    				.addComponent(getJButton4(), GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE, GroupLayout.PREFERRED_SIZE)
    				.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
    		}
    		return jDialog2;
    	}
     
    	private JLabel getAboutLabel() {
    		if(aboutLabel == null) {
    			aboutLabel = new JLabel();
    			aboutLabel.setText("This application was made with Jigloo");
    			aboutLabel.setBorder(new LineBorder(new java.awt.Color(0,0,0), 1, false));
    			aboutLabel.setHorizontalAlignment(SwingConstants.CENTER);
    		}
    		return aboutLabel;
    	}
     
    	private JButton getJButton4() {
    		if(jButton4 == null) {
    			jButton4 = new JButton();
    			jButton4.setText("Ok");
    			jButton4.setAction(getOkAction());
    		}
    		return jButton4;
    	}
     
    	private AbstractAction getOkAction() {
    		if(okAction == null) {
    			okAction = new AbstractAction("Ok", null) {
    				public void actionPerformed(ActionEvent evt) {
    					getJDialog2().dispose();
    				}
    			};
    		}
    		return okAction;
    	}
     
    	private AbstractAction getBrowseAction() {
    		if(browseAction == null) {
    			browseAction = new AbstractAction("Browse...", null) {
    				public void actionPerformed(ActionEvent evt) {
    					getJFileChooser1().showOpenDialog(rootPane);
    					getJFileChooser1().setLocation(getLocationOnScreen());
    					getJFileChooser1().setVisible(true);
    					jTextField1.setText(getJFileChooser1().getSelectedFile().getName());
    					BufferedImage img = null;
    					try {
    						img = ImageIO.read(new File((getJFileChooser1().getSelectedFile().getAbsolutePath())));
    					} catch (IOException e) {
    						// TODO Auto-generated catch block
    						e.printStackTrace();
    					}
    					Graphics g = img.getGraphics();
    					canvas1.paint(g);
    				}
    			};
    		}
    		return browseAction;
    	}
     
     
    	private JFileChooser getJFileChooser1() {
    		if(jFileChooser1 == null) {
    			jFileChooser1 = new JFileChooser();
    		}
    		return jFileChooser1;
    	}
     
    	private AbstractAction getBrowsedFileAction() {
    		if(browsedFileAction == null) {
    			browsedFileAction = new AbstractAction("file", null) {
    				public void actionPerformed(ActionEvent evt) {
    					jTextField1.setText(getJFileChooser1().getSelectedFile().getName());
    				}
    			};
    		}
    		return browsedFileAction;
    	}
     
    	private Canvas getCanvas1() {
    		if(canvas1 == null) {
    			canvas1 = new Canvas();
    		}
    		return canvas1;
    	}
     
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,529
    My Mood
    Hungover
    Thanks
    144
    Thanked 647 Times in 552 Posts

    Default Re: Starting a Slideshow Program... Lost

    Yikes, that's way too much code to sift through. Get your problem boiled down to an SSCCE, and we'll go from there.

Similar Threads

  1. New to Programming, Starting college for computer engineering
    By TheBLC84 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 17th, 2010, 05:06 AM
  2. starting to make a simple database
    By chronoz13 in forum JDBC & Databases
    Replies: 1
    Last Post: January 15th, 2010, 02:06 PM
  3. Help starting program, need done by Nov 4
    By raidcomputer in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 4th, 2009, 07:22 PM
  4. Need help starting a program
    By Mickey2315 in forum Java Theory & Questions
    Replies: 2
    Last Post: September 7th, 2009, 03:21 PM
  5. Starting a java programming career
    By oss_2008 in forum The Cafe
    Replies: 3
    Last Post: July 8th, 2009, 08:45 AM