المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : معاوز مساعدة سريعه من أخواني ...((أكواد جافا))


eshrag.net
08-05-2010, 06:12 PM
<div>السلام عليكم أخواني و أخواتي
ندخل في الموضوع ,,
عندي الكودات وما قدرت أعدلهم فأرجوا من اي واحد خبير في الجافا ما يبخل علينا
عاوز يكونوا ثلاث
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

السؤال :
Write a Java application using GUI that simulates a soft drink vending machine. The simulated machine dispenses the following soft drinks: Coca Cola, Lemon-Lime Soda, Grape Soda, Root Beer, and Bottled Water. Each drink has different cost each to purchase.

The user interface should provide a Frame showing the simulated machine interface. The machine should have a supply of 10 of each of the drinks. It should also have a textfield where the user can enter the amount of money he or she is giving to the machine. The user can click on a button to select a drink to dispense. The application should also display the amount of change it is giving back to the user. It should also keep track of its inventory of drinks and inform user if he or she has selected a drink that is out of stock. Include necessary exceptions handling in your code. Perform also validation on input fields such as selecting a drink with no money entered or selecting a drink with inadequate amount of money.

Define and use a class named StockItem in your application to represent an object of each drink provided by the machine. Include suitable attributes and methods in your class.




<div style="margin:20px; margin-top:5px"> كود بلغة HTML:
import java.awt.Graphics;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.TextField;

import java.awt.event.MouseEvent;
import java.awt.image.*;
import java.awt.Rectangle;
import java.io.File;
import java.io.IOException;


import javax.imageio.ImageIO;
import javax.swing.JFrame;


@SuppressWarnings("serial")
public class vendingMachine extends JFrame {
static final int width = 600,
height = 400,
initialSupply = 10,
rectWidth = 100,
rectHeight = 150;

StockItem[] drinks = new StockItem[5];
Rectangle[] StockItemRects = new Rectangle[5];

TextField userMoney;
Label userMoneyLabel,userChangeLabel,errorMsgLabel;

void DrawDrink(Graphics gr,Rectangle rect,StockItem drink) throws IOException{
// draws the supply
gr.drawString(String.format("Supply : %d",drink.getCurrentSupply()), rect.x, rect.y);
// draws the company's drink logo
BufferedImage im = ImageIO.read(getClass().getResource(drink.getImage Path()));
gr.drawImage(im,rect.x,rect.y+15,rect.width,rect.h eight - 50, null);
// and the cost
gr.drawString(String.format("Cost : %.2f",drink.getCost()), rect.x, rect.height+30);
}
void DrawDrinks(Graphics gr) throws IOException{
Rectangle rct = new Rectangle(50,50,rectWidth,rectHeight);
for(int i=0; i<span style="color:#000080">