1 Replies - 445 Views - Last Post: 09 February 2013 - 10:18 AM Rate Topic: -----

#1 Brovahkiin501  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 48
  • Joined: 01-October 12

Create Front View of Vending Machine Program

Posted 07 February 2013 - 04:47 PM

Hi everyone! So I am trying to create a front view of a vending machine program. I will post my program below. It is working right for the most part, except I need the parts that say "Price," "$1.25" and "Enter money here..." to be below the image of the dollar bill and I'm not sure how to do that. I also need to create another button that says "Return amount" to be right below the four buttons, W, S, P, and C. Also, for those 4 buttons, you can't see the whole "Choose one" and I'm not sure how to fix that /: If anybody can help me with those questions, it would be much appreciated!

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.io.File;

public class Vending extends JFrame {


	public Vending(String s) {

		super(s);

		JPanel p1 = new JPanel();
		p1.setLayout(new GridLayout(4, 1));
		ImageIcon waterIcon = new ImageIcon("water_bottle.bmp");
		ImageIcon waterIcon2 = new ImageIcon(waterIcon.getImage().getScaledInstance((int)100, (int)100, java.awt.Image.SCALE_SMOOTH));
		ImageIcon sodaIcon = new ImageIcon("coke_bottle.bmp");
		ImageIcon sodaIcon2 = new ImageIcon(sodaIcon.getImage().getScaledInstance((int)60, (int)158, java.awt.Image.SCALE_SMOOTH));
		ImageIcon pretzelIcon = new ImageIcon("pretzels.bmp");
		ImageIcon pretzelIcon2 = new ImageIcon(pretzelIcon.getImage().getScaledInstance((int)90, (int)100, java.awt.Image.SCALE_SMOOTH));
		ImageIcon chocolateIcon = new ImageIcon("chocolate_bar.bmp");
		ImageIcon chocolateIcon2 = new ImageIcon(chocolateIcon.getImage().getScaledInstance((int)80, (int)63, java.awt.Image.SCALE_SMOOTH));
		JButton water1 = new JButton(waterIcon2);
		JButton soda1 = new JButton(sodaIcon2);
		JButton pretzel1 = new JButton(pretzelIcon2);
		JButton chocolate1 = new JButton(chocolateIcon2);
		p1.add(water1);
		p1.add(soda1);
		p1.add(pretzel1);
		p1.add(chocolate1);
		p1.setBorder(new TitledBorder("Goodies"));
		


		JPanel p2 = new JPanel();
		p2.setLayout(new GridLayout(4, 1));
		p2.setCursor(new Cursor(Cursor.HAND_CURSOR));
		JButton water = new JButton("W");
		JButton soda = new JButton("S");
		JButton pretzel = new JButton("P");
		JButton chocolate = new JButton("C");
		water.setToolTipText("Water");
		soda.setToolTipText("Soda");
		pretzel.setToolTipText("Pretzel");
		chocolate.setToolTipText("Chocolate");
		p2.add(water);
		p2.add(soda);
		p2.add(pretzel);
		p2.add(chocolate);
		p2.setBorder(new TitledBorder("Choose one"));
	
		JPanel p3 = new JPanel();
		p3.setLayout(new FlowLayout(FlowLayout.RIGHT));
		ImageIcon dollarIcon = new ImageIcon("dollar_bill.bmp");
		ImageIcon dollarIcon2 = new ImageIcon(dollarIcon.getImage().getScaledInstance((int)72, (int)30, java.awt.Image.SCALE_SMOOTH));
		JButton dollar = new JButton(dollarIcon2);
		p3.add(dollar);
		
		JPanel p4 = new JPanel();
		p4.setLayout(new FlowLayout(FlowLayout.RIGHT));
		JLabel price = new JLabel("Price");
		JTextField dollars = new JTextField("$1.25");
		JTextField enter = new JTextField("Entery money here...");
		p4.add(price);
		p4.add(dollars);
		p4.add(enter);
		
		JPanel p5 = new JPanel();
		p5.setLayout(new FlowLayout());
		JButton item = new JButton("This is where you get your item!");
		p5.add(item);

		setLayout(new BorderLayout());
		add(p1, BorderLayout.WEST);
		add(p2, BorderLayout.EAST);
		add(p3, BorderLayout.NORTH);
		add(p5, BorderLayout.SOUTH);
		add(p4);
	

	}

	public static void main(String[] args) {
		Vending frame = new Vending("THE FRONT VIEW OF A VENDING MACHINE");
		frame.setSize(400, 800);
		frame.setLocationRelativeTo(null);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}


}






Is This A Good Question/Topic? 0
  • +

Replies To: Create Front View of Vending Machine Program

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: Create Front View of Vending Machine Program

Posted 09 February 2013 - 10:18 AM

We need runnable code really. Please post a zip including your images AFTER altering your image loading code per the following:

http://technojeeves....a-with-netbeans
http://technojeeves....va-with-eclipse
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1