Neatbeens Programa Balanza

Páginas: 2 (365 palabras) Publicado: 20 de septiembre de 2012
* import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Balanza extends JFrame {
JLabel l1 = new JLabel("+ / - Peso1");
JLabel l2 = newJLabel("+ / - Peso2");
JLabel ltot1 = new JLabel();
JLabel ltot2 = new JLabel();
JTextField t1 = new JTextField(5);
JTextField t2 = new JTextField(5);
JButton b1 = new JButton("OK");
doublep1tot,p2tot;
public static void main(String []linea) {
Balanza marco = new Balanza("Balanza");
WindowAdapter oye = new WindowAdapter() {
public void windowClosing(WindowEvent e1) {
System.exit(0);
}
};marco.addWindowListener(oye);
marco.setSize(600,600);
marco.setVisible(true);
}
Balanza(String nombre) {
super (nombre);
getContentPane().setLayout(new FlowLayout());
JPanel p = newJPanel(new GridLayout(3,3));
p.add(l1);
p.add(t1);
p.add(ltot1);
p.add(l2);
p.add(t2);
p.add(ltot2);
p.add(b1);
p1tot = p2tot = 0;
getContentPane().add(p);
ActionListener oye = new ActionListener() {public void actionPerformed(ActionEvent e1) {
String tp;
double peso1, peso2, x1, y1, x2, y2, ang;
Graphics g=getGraphics();
g.setColor(Color.white);
g.fillRect(0,150,600,450);g.setColor(Color.black);
tp=t1.getText();
peso1 = Double.parseDouble (tp);
tp=t2.getText();
peso2 = Double.parseDouble (tp);
p1tot = p1tot + peso1;
p2tot = p2tot + peso2;
ltot1.setText("" + p1tot);ltot2.setText("" + p2tot);
ang = (p1tot - p2tot)/4.0;
ang = ang * Math.PI / 180.0;
if (ang > 0) {
x1 = 300 + 200 * Math.cos(ang);
y1 = 200 + 200 * Math.sin(ang);
x2 = 300 - 200 * Math.cos(ang);
y2 =200 - 200 * Math.sin(ang);
g.drawLine ((int)x1,400-(int)y1,(int)x2,400-(int)y2);
g.drawString("" + p2tot,(int)x1,400 - (int)y1);
g.drawString("" + p1tot,(int)x2,400 - (int)y2);
g.drawLine(300,400,300,200);
}
else if (ang == 0) {
g.drawLine (200,200,400,200);
g.drawString("" + p2tot,400,200);
g.drawString("" + p1tot,200,200);
g.drawLine (300,400,300,200);
}
else {
ang = -ang;
x2 =...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Balanza
  • Balanzas
  • la balanza
  • balanza
  • balanza
  • Balanzas
  • Balanzas
  • Balanza

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS