Sunteți pe pagina 1din 9

Ministerul Educaiei a Republicii Moldova

Universitatea de Stat din Moldova


Facultatea Matematic si Informatic

Lucrare de laborator Nr.1


Obiect: Java Pe Calculator

Chiinu 2014

Cod sursa:
import java.applet.*;
1

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class My_applette extends Applet implements ActionListener
{ String den_petrecere, slider, tip_party_string, where, tip_torta,rez;
Image img_title_left, img_error, z_1, z_2, p_1, p_2, f_1, n_1, m_1;
JSlider quantity;
Choice where_party, tip_party,torta;
Image bg_1, bg_2, bg_3, bg_4;
Button go;
public void init()
{
setSize(1000, 700);
setBackground(Color.black);
den_petrecere=" Party of Moldova";
slider = "Pipols of party";
tip_party_string = "Tip of party";
where = "Where is The Party";
tip_torta = "Cake for Party";
rez="Pagube>>>>>";
img_title_left = getImage(getDocumentBase(),"1.jpg");
img_error = getImage(getDocumentBase(), "2.jpg");
z_1 = getImage(getDocumentBase(), "z_1.jpg");
z_2 = getImage(getDocumentBase(), "z_2.jpg");
p_1 = getImage(getDocumentBase(), "p_1.jpg");
p_2 = getImage(getDocumentBase(), "p_2.jpg");
f_1 = getImage(getDocumentBase(), "f_1.jpg");
2

n_1 = getImage(getDocumentBase(), "n_1.jpg");


m_1 = getImage(getDocumentBase(), "m_1.jpg");
bg_1 = getImage(getDocumentBase(), "bg_1.jpg");
bg_2 = getImage(getDocumentBase(), "bg_2.jpg");
bg_3 = getImage(getDocumentBase(), "bg_3.jpg");
bg_4 = getImage(getDocumentBase(), "bg_4.jpg");
quantity = new JSlider(0,100);
quantity.setMajorTickSpacing(10);
quantity.setPaintLabels(true);
quantity.setBackground(Color.CYAN);
add(quantity);

tip_party = new Choice();


tip_party.insert("Wedding Party", 1);
tip_party.insert("Christening Party", 2);
tip_party.insert("Birthday Party", 3);// Party
tip_party.insert("Girl Party", 4);//
tip_party.insert("Boys Party", 5);
add(tip_party);
where_party = new Choice();
where_party.insert("Adam&Eva", 1);
where_party.insert("Disco", 2);// Party
where_party.insert("Andy's Pizza", 3);//
where_party.insert("Plai", 4);
add(where_party);
torta = new Choice();
torta.insert("Gingasie", 1);
3

torta.insert("Diplomat", 2);
torta.insert("Medovii", 3);// Party
torta.insert("Capucino", 4);//
add(torta);
go = new Button("Start of Party");
go.addActionListener(this);
add(go);
}
public void paint(Graphics g)
{
//fonturi
Font f = new Font("Algerian", Font.BOLD, 50);
Font ff = new Font("Algerian", Font.BOLD, 36);
Font fff = new Font("Algerian", Font.BOLD + Font.ITALIC, 20);

//titlul
g.setColor(Color.red);
g.setFont(f);
g.drawString(den_petrecere, 420, 50);
//showStatus(" Displaying Text at Center of Screen");

//img 1stinga sus


g.drawImage(img_title_left, 70, 20, this);

//tip of party
g.setColor(Color.green);
4

g.setFont(ff);
g.drawString(tip_party_string, 10, 250);
tip_party.setBounds(15, 265, 100, 20);
//where
g.setColor(Color.blue);
g.setFont(ff);
g.drawString(where, 10, 320);
where_party.setLocation(15, 332);
//tip torta
g.setColor(Color.red);
g.setFont(ff);
g.drawString(tip_torta, 10, 420);
torta.setBounds(15, 430, 100, 20);
//sliderul
g.setColor(Color.orange);
g.setFont(ff);
g.drawString(slider, 10, 500);
quantity.setBounds(10, 520, 400, 50);
g.setColor(Color.black);
g.drawRect(8, 480, 403, 55);

//rezulatul party
g.setFont(fff);
g.setColor(Color.red);
g.drawString(rez, 450, 500)
//butonul
go.setLocation(300, 600);
5

// wedding
if(tip_party.getSelectedItem().equals("Wedding Party") &&
where_party.getSelectedItem().equals("Adam&Eva")
&& (torta.getSelectedItem().equals("Gingasie ") ||
torta.getSelectedItem().equals("Diplomat")) && quantity.getValue() < 20)
{
g.drawImage(z_1, 500, 150, this);

if(tip_party.getSelectedItem().equals("Wedding Party") &&


where_party.getSelectedItem().equals("Plai")
&& (torta.getSelectedItem().equals("Gingasie") ||
torta.getSelectedItem().equals("Medovii")) && quantity.getValue() < 40)
{
g.drawImage(z_2, 500, 150, this);

// Christening Party
if(tip_party.getSelectedItem().equals("Christening Party") &&
where_party.getSelectedItem().equals("Adam&Eva")
&& torta.getSelectedItem().equals("Capucino") && quantity.getValue() < 6)
{
g.drawImage(p_1, 500, 150, this);

if(tip_party.getSelectedItem().equals("Christening Party") &&


where_party.getSelectedItem().equals("Plai")
&& torta.getSelectedItem().equals("Capucino") && quantity.getValue() < 80)
{
g.drawImage(p_2, 500, 150, this);

}
//Birthday Party
if(tip_party.getSelectedItem().equals("Birthday Party") &&
where_party.getSelectedItem().equals("Andy's Pizza")
&& (torta.getSelectedItem().equals("Gingasie") ||
torta.getSelectedItem().equals("Capucino")) && quantity.getValue() < 80)
{
g.drawImage(f_1, 500, 150, this);

}
//Girl Party
if(tip_party.getSelectedItem().equals("Girl Party") &&
where_party.getSelectedItem().equals("Disco")
&& (torta.getSelectedItem().equals("Gingasie") ||
torta.getSelectedItem().equals("Medovii")) && quantity.getValue() <= 100)
{
g.drawImage(n_1, 500, 150, this);

}
//Boys Party
if(tip_party.getSelectedItem().equals("Boys Party") &&
where_party.getSelectedItem().equals("Disco")
&& torta.getSelectedItem().equals("Diplomat") && quantity.getValue() <= 100)
{
7

g.drawImage(m_1, 500, 150, this);


}
}

// }

public void actionPerformed(ActionEvent e)


{
if ( where_party.getSelectedItem().equals("Adam&Eva"))
this.setBackground(Color.green);
if ( where_party.getSelectedItem().equals("Disco"))
this.setBackground(Color.gray);
if ( where_party.getSelectedItem().equals("Andy's Pizza"))
this.setBackground(Color.blue);
if ( where_party.getSelectedItem().equals("Plai"))
this.setBackground(Color.orange);

if ((quantity.getValue() >= 0)&&(quantity.getValue() < 10))


rez = rez + "10%"+ getParameter("parametru");

if ((quantity.getValue() >= 10)&&(quantity.getValue() < 20))


rez = rez + "20%"+ getParameter("parametru");

if ((quantity.getValue() >= 20)&&(quantity.getValue() < 30))


rez = rez + "30%"+ getParameter("parametru");

if ((quantity.getValue() >= 30)&&(quantity.getValue() < 40))


rez = rez + "40%"+ getParameter("parametru");

if ((quantity.getValue() >= 40)&&(quantity.getValue() < 50))


rez = rez + "50%"+ getParameter("parametru");

if ((quantity.getValue() >= 50)&&(quantity.getValue() < 60))


rez = rez + "60%"+ getParameter("parametru");

if ((quantity.getValue() >= 60)&&(quantity.getValue() < 70))


rez = rez + "70%"+ getParameter("parametru");

if ((quantity.getValue() >= 70)&&(quantity.getValue() < 80))


rez = rez + "80%"+ getParameter("parametru");

if ((quantity.getValue() >= 80)&&(quantity.getValue() < 90))


rez = rez + "90%"+ getParameter("parametru");

if ((quantity.getValue() >= 90)&&(quantity.getValue() < 100))


rez = rez + "100%"+ getParameter("parametru");

repaint();
}

S-ar putea să vă placă și