Sei sulla pagina 1di 7

***PRACTICA HARDWARE***

class public Computadora


{
MonitorP monitor = new MonitorP();
Drive dvd = new Drive();
Teclado teclado = new Teclado();
Memoria memoria = new Memoria();
}
//Describe los Drives de tu computadora
class Drive
{
String drive = " CD-DVD";
}
//Describe la memoria de tu computadora
class Memoria
{
String memoria = " Ram tipo DDR2, 2GB";
}
//Describe el Monitor de tu Computadora
class MonitorP
{
String tipoMonitor = " HGVA a Color";
}


//Describe la Teclado de tu computadora
class Teclado
{
String teclado = " Alfanumerico QWERTY";
}

public class Salida Extends Computadora
public static void main (String[] args)
{
Salida cl = new Salida();
System.out.println(cl.monitor.tipoMonitor);
System.out.println(cl.dvd.drive);
System.out.println(cl.teclado.teclado);
System.out.println(cl.memoria.memoria);
}
***PRACTICA VENTANA EVENTOS***
import java.awt.*;
import java.awt.event.*;
public class VentanaEventos extends Frame implements ActionListener
{
Label e = new Label ("Observa lo que Escribes");
Button b = new Button("Aceptar");
Button b2 = new Button("Borrar");
TextField t = new TextField("Blanquear y Escribir");

public VentanaEventos()
{
add(t, "North");
add(b);
add(b2,"East");
add(e, "South");
b.addActionListener(this);
b2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
e.setText("");
t.setText("");
}
});
addWindowListener( new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
public void windowIconified(WindowEvent we)
{
System.out.println("minimizado");
}
}
);


setSize(200, 120);
setVisible(true);
}

/* public void windowDeactivated(WindowEvent we)
{

}
*/
public void actionPerformed(ActionEvent ae)
{
String c = ae.getActionCommand();
/* if (c.equals("OK"))
{
*/ e.setText(t.getText());
/*}
else
{
e.setText("");
t.setText("");
}
*/ }

public static void main(String[] args)
{
new VentanaEventos();
}
}





*** PRACTICA CALCULADORA INTEGRADA POR MODULOS***
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

class SwingCalculadora
{
public static void main(String[] args)
{
JFrame frame = new Calculadora();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
//PROGRAMA INTEGRADO EN MODULOS
//1 MODULO
import java.awt.*;
import java.awt.event.*;
import java.swing.*;
import javax.swing.event.*;

class Calculadora extends JFrame
{
private final Font BIGGER_FONT = new Font("monspaced", Font.PLAIN, 20);
private JTextField textfield;
private boolean number = true;
private string equalOp="=";
private CalculadoraOp op= new CalculadoraOp();
//

//PROGRAMA INTEGRADO EN MODULOS
//2 MODULO

public Calculadora()
{
textfield =new JTextField("0", 12);
textfield.setHorizontalAligment(JTextField.RIGHT);
textfield.setFont(BIGGER_FONT);

ActionListener numberListener=new NumberListener();
String buttonOrder="1234567890";
JPanel buttonPanel =new JPanel();
buttonPanel.setLayout(new GridLayout(4,4,4,4));
for (int i=0;i<buttonOrder.leght();i++){
String key= buttonOrder.substring(i, i+1);
if (key.equals("")){
buttonPanel.add(new JLabel(""));
} else {
JButton button =new JButton(key);
button.addActionListener(numberListener);
button.setFont(BIGGER_FONT);
button.Panel.add(button);
}
}
//PROGRAMA INTEGRADO EN MODULOS
// 3 MODULO

ActionListener operatorListener = new OperatorListener[]
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(4, 4, 4, 4));
String[] opOrder = {"+", "-", "*", "/", "=", "C"};
for (int i = 0; i <opOrder.lenght; i++) {
JButton button = new JButton(opOrder[i]);
button.addActionListener(operatorListener);
button.setFont(BIGGER_FONT);
panel.add(button);
}

//-----------------------------------------------------------
//PROGRAMA INTEGRADO EN MODULOS
//4 MODULO
JPanel pan = new JPanel();
pan.setLayout(new BorderLayout(4, 4));
pan.add(textfield, BorderLayout.NORTH);
pan.add(buttonPanel ,BorderLayout.CENTER);
pan.add(panel , BorderLayout.EAST );
this.setTitle("CALCULADORA INTEGRAL");
this.setResizable (false);
}
private void action() {
number = true;
textfield.setText("0");
equalOp = "=";
Op.setTotal ("o"); }
}

//PROGRAMA INTEGRADO EN MODULOS
//5 MODULO
class OperatorListener implements ActionListener{
public void actionPerformed (ActionEvent e){
if (number){
action();
textfield.setText("0");
} else{
number =true;
String displayText = textfield.getText();
if (equalOp.esquals("=")){
op.setTotal (displayText);
} else if (equalOp.esquals("+")){
op.setTotal (displayText);
} else if (equalOp.esquals("-")){
op.setTotal (displayText);
} else if (equalOp.esquals("*")){
op.setTotal (displayText);
} else if (equalOp.esquals("/")){
op.setTotal (displayText);
}
textfield.setText("" + op.getTotalStrig());
equalOp= e. get;
{
ActionCommand();
}
}
}
//----------------------------------------------------------
//PROGRAMA INTEGRADO EN MODULOS
//6 MODULO

class NumberListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
String digit = event.getActionCommand();
if (number) {
textfield.setText(digit);
number = false;
} else {
textfield.setText(textfield.getText() + digit);
}
}
}

//----------------------------------------------------------

//PROGRAMA INTEGRADO EN MODULOS
//7 MODULO

public class CalculadoraOp{
private int total;
public CalculadoraOp(){
total = 0;
}
pub
lic; String getTotalString(); {
return ""+total;
}
public void setTotal(String n) {
total = converterToNumber(n);
}
public void add(String n) {
total += converterToNumber(n);
}
public void subtract(String n) {
total -= converterToNumber(n);
}
public void multiply(String n) {
total *= converterToNumber(n);
}
public void divide(String n) {
total /= converterToNumber(n);
}
private int converterToNumber (String n){
return Integer.parseInt(n);
}
}
}

Potrebbero piacerti anche