0% found this document useful (0 votes)
44 views

Lata Latb Latc Reztip Rezarie Rezper Ja JB JC Tip Arie Perimetru

The document contains code for 4 Java applets: 1. The first applet (EXER1) calculates the type, area, and perimeter of a triangle given 3 side lengths. 2. The second applet (EXER2) calculates the cost of fuel for a trip given price per liter, consumption, and distance. 3. The third applet contains code to calculate call costs given duration and call type (domestic, other operator, international). 4. The fourth applet contains similar code to the first for triangle properties but is otherwise blank.

Uploaded by

Victoria Oprea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Lata Latb Latc Reztip Rezarie Rezper Ja JB JC Tip Arie Perimetru

The document contains code for 4 Java applets: 1. The first applet (EXER1) calculates the type, area, and perimeter of a triangle given 3 side lengths. 2. The second applet (EXER2) calculates the cost of fuel for a trip given price per liter, consumption, and distance. 3. The third applet contains code to calculate call costs given duration and call type (domestic, other operator, international). 4. The fourth applet contains similar code to the first for triangle properties but is otherwise blank.

Uploaded by

Victoria Oprea
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

import java.awt.

* ;
import javax.swing.*;
import java.awt.event.*;
public class EXER1 extends JApplet{
JLabel latA, latB, latC, rezTip,rezArie, rezPer;
JTextField jA, jB, jC; JButton tip, arie,perimetru;

public void init() {


setSize(600,200);
setLayout(new GridLayout(6,2));
latA = new JLabel("Introduceti latura A");
jA = new JTextField(8); add(latA); add(jA);

latB = new JLabel("Introduceti latura B");


jB = new JTextField(8); add(latB); add(jB);

latC = new JLabel("Introduceti latura C");


jC = new JTextField(8); add(latC); add(jC);

tip = new JButton("Determina tip");


tip.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int a = Integer.parseInt(jA.getText());
int b = Integer.parseInt(jB.getText());
int c = Integer.parseInt(jC.getText());
if (a<=0 || b<=0 || c<=0)
rezTip.setText("nu sunt laturi ale unui triunghi");
else
if (a+b<=c || a+c<=b || b+c<=a)
rezTip.setText("nu sunt laturi ale unui triunghi");
else
if(a == b && b == c) rezTip.setText("echilateral");
else
if(a == b || a == c || b == c)
rezTip.setText("isoscel");
else rezTip.setText("Triunghiul este oarecare");
}
});

add(tip);
rezTip = new JLabel(); add(rezTip);
arie = new JButton("Determina aria");
arie.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int a = Integer.parseInt(jA.getText());
int b = Integer.parseInt(jB.getText());
int c = Integer.parseInt(jC.getText());
if (a<=0 || b<=0 || c<=0)
rezTip.setText("nu sunt laturi ale unui triunghi");
else
if (a+b<=c || a+c<=b || b+c<=a)
rezTip.setText("nu sunt laturi ale unui triunghi");
else {
double p = (a+b+c)/2;
double s = Math.sqrt(p*(p-a)*(p-b)*(p-c));
rezArie.setText("Aria triunghiului = " +s);
} }
});

add(arie); rezArie = new JLabel(); add(rezArie);

perimetru = new JButton("Determina perimetrul");


perimetru.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int a = Integer.parseInt(jA.getText());
int b = Integer.parseInt(jB.getText());
int c = Integer.parseInt(jC.getText());
if (a<=0 || b<=0 || c<=0)
rezTip.setText("nu sunt laturi ale unui triunghi");
else if (a+b<=c || a+c<=b || b+c<=a)
rezTip.setText("nu sunt laturi ale unui triunghi");
else {
double p = a+b+c;
rezPer.setText("Perimetru triunghiului = " +p);
} }
});
add(perimetru); rezPer = new JLabel(); add(rezPer);
setVisible(true);

}
}
import java.awt.* ;
import javax.swing.*;
import java.awt.event.*;
public class EXER2 extends JApplet{
JLabel lPret, lCons, lDist, rez;JTextField jPret, jCons,
jDist;
JButton b;
public void init() {
setLayout(new GridLayout(4,2));
setSize(400,200);
lPret = new JLabel("Pret combustibil (lei/litru");
jPret = new JTextField(8); add(lPret); add(jPret);

lCons = new JLabel("Consumul (litri la 100 km");


jCons = new JTextField(8); add(lCons); add(jCons);

lDist = new JLabel("Distanta");


jDist = new JTextField(8); add(lDist); add(jDist);

b = new JButton("Calculeaza");
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
double pret = Double.parseDouble(jPret.getText());
double dist = Double.parseDouble(jDist.getText());
double cons = Double.parseDouble(jCons.getText());
double x = ((dist*cons)/100)*pret;
rez.setText(String.valueOf(x));
}
});
add(b);
rez = new JLabel(); add(rez);
}
}
import java.awt.* ;
import javax.swing.*;
import javax.swing.border.TitledBorder;

import java.awt.event.*;
public class EXER4 extends JApplet{
JLabel jl1, rez;
JTextField jConv;
JRadioButton jrb1, jrb2,jrb3;
JButton calc;
public void init() {
setSize(400,300);
setLayout(new GridLayout(5,1));
jl1 = new JLabel("Durata convorbirii (secunde)");
add(jl1);
jConv = new JTextField(8);
add(jConv);
JPanel p = new JPanel();
p.setBorder(new TitledBorder("Tipul convorbirii"));
ButtonGroup jr = new ButtonGroup();
jrb1 = new JRadioButton("in retea",true);
jrb2 = new JRadioButton("cu alt operator national",false);
jrb3 = new JRadioButton("international",false);
jr.add(jrb1); jr.add(jrb2);jr.add(jrb3);
p.add(jrb1); p.add(jrb2);p.add(jrb3);
add(p);
calc = new JButton("Calculeaza");
calc.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
double sec = Double.parseDouble(jConv.getText());
double cost=0;
if (jrb1.isSelected()) cost = sec*0.75;
if (jrb2.isSelected()) cost = sec*1.76;
if (jrb3.isSelected()) cost = sec*2.50;
rez.setText(String.valueOf(cost));
}

});
rez = new JLabel();
add(calc);add(rez);

You might also like