Páginas

domingo, 27 de noviembre de 2011

Examen en java





package Examen;
import java.awt.Color;
import java.awt.Graphics;


/**
*
* @author Peter Ju
*/
public class NewJFrame extends javax.swing.JFrame {

/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(204, 204, 204));

jPanel1.setBackground(new java.awt.Color(0, 0, 0));
jPanel1.setPreferredSize(new java.awt.Dimension(550, 550));

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 550, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 550, Short.MAX_VALUE)
);

jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton1.setText("Dibuja");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(181, 181, 181)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(23, 23, 23))
);

pack();
}//


private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
Dibuja();


}

public void Dibuja()
{


Graphics g ;
g = jPanel1.getGraphics();
g.setColor(Color.green);
//g = this.getGraphics();

int i , x, posx, posy;
float y;

int Height = jPanel1.getHeight();
int Width = jPanel1.getWidth();


g.drawRect(10, 10,Width-10,Height-10);
posx = Width -12;
posy = Height -12;

for(i =0, x = posx,y = posy-200;i<21;x-=15,y+=10,i++)
{
g.drawLine(x, posy, posx,(int)y);

}

posx = 11;
posy = Height-12;
for(i =0, x = posx,y = posy-200;i<21;x+=15,y+=10,i++)
{
g.drawLine(x, posy, posx,(int)y);
}

posx = 11;
posy = 11;
for(i =0, x = posx,y = posy+200;i<21;x+=15,y-=10,i++)
{
g.drawLine(x, posy, posx,(int)y);
}

posx = Width -12;
posy = 11;
for(i =0, x = posx,y = posy+200;i<21;x-=15,y-=10,i++)
{
g.drawLine(x, posy, posx,(int)y);
}


//jPanel1


}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
// End of variables declaration

}

No hay comentarios:

Publicar un comentario