Created
April 7, 2013 03:20
-
-
Save joepreludian/5328777 to your computer and use it in GitHub Desktop.
Arquivo Java com anotações do hangout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package bandeira; | |
import java.awt.Color; | |
import java.awt.Graphics; | |
import java.awt.GraphicsConfiguration; | |
import java.awt.Point; | |
import java.awt.Polygon; | |
import javax.swing.JPanel; | |
/** | |
* | |
* @author joey | |
*/ | |
public class GLSdoSul extends javax.swing.JFrame { | |
/** | |
* Creates new form GLSdoSul | |
*/ | |
public GLSdoSul() { | |
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") | |
// <editor-fold defaultstate="collapsed" desc="Generated Code"> | |
private void initComponents() { | |
bandeira = new javax.swing.JPanel(); | |
jLabel1 = new javax.swing.JLabel(); | |
botaoGenerate = new javax.swing.JButton(); | |
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); | |
bandeira.setBackground(new java.awt.Color(255, 255, 255)); | |
org.jdesktop.layout.GroupLayout bandeiraLayout = new org.jdesktop.layout.GroupLayout(bandeira); | |
bandeira.setLayout(bandeiraLayout); | |
bandeiraLayout.setHorizontalGroup( | |
bandeiraLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) | |
.add(0, 462, Short.MAX_VALUE) | |
); | |
bandeiraLayout.setVerticalGroup( | |
bandeiraLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) | |
.add(0, 293, Short.MAX_VALUE) | |
); | |
jLabel1.setText("GLS do Sul"); | |
botaoGenerate.setText("Generate"); | |
botaoGenerate.addActionListener(new java.awt.event.ActionListener() { | |
public void actionPerformed(java.awt.event.ActionEvent evt) { | |
botaoGenerateActionPerformed(evt); | |
} | |
}); | |
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); | |
getContentPane().setLayout(layout); | |
layout.setHorizontalGroup( | |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) | |
.add(layout.createSequentialGroup() | |
.add(21, 21, 21) | |
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) | |
.add(layout.createSequentialGroup() | |
.add(jLabel1) | |
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
.add(layout.createSequentialGroup() | |
.add(bandeira, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) | |
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) | |
.add(layout.createSequentialGroup() | |
.add(393, 393, 393) | |
.add(botaoGenerate) | |
.add(0, 21, Short.MAX_VALUE)) | |
); | |
layout.setVerticalGroup( | |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) | |
.add(layout.createSequentialGroup() | |
.add(24, 24, 24) | |
.add(jLabel1) | |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) | |
.add(bandeira, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) | |
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) | |
.add(botaoGenerate) | |
.addContainerGap(25, Short.MAX_VALUE)) | |
); | |
pack(); | |
}// </editor-fold> | |
private void renderEstrela(Graphics g, Color cor, int x, int y, double ratio) | |
{ | |
//Pontos do X e Y da estrela | |
int[] xPoints = {47, 58, 93, 64, 75, 47, 21, 31, 3, 37}; | |
int[] yPoints = {0, 32, 32, 52, 86, 65, 86, 52, 32, 32}; | |
int nPoints = xPoints.length; | |
//Calculando deslocamento e tamanho de X | |
for (int i=0; i < xPoints.length; i++) | |
xPoints[i] = (int) (ratio * xPoints[i]) + x; | |
//Calculando deslocamento e tamanho de Y | |
for (int i=0; i < yPoints.length; i++) | |
yPoints[i] = (int) (ratio * yPoints[i]) + y; | |
//Seta o tamanho do polígono; | |
Polygon star = new Polygon (xPoints, yPoints, nPoints); | |
//Preenchendo cor | |
g.setColor(cor); | |
//Desenho em si | |
g.fillPolygon(star); | |
} | |
private void renderBandeira(JPanel p) | |
{ | |
//Coletando os dados gráficos | |
Graphics g = p.getGraphics(); | |
/* | |
* Aqui onde desenhamos | |
*/ | |
//Renderizando caixa | |
g.setColor(Color.GREEN); | |
g.fillRect( | |
0, | |
0, | |
this.getPercentSize(p, 'x', 100), | |
this.getPercentSize(p, 'y', 100) | |
); | |
//Renderizando estrela | |
/* | |
this.renderEstrela( | |
g, //Objeto Graphics | |
Color.WHITE, //Cor | |
0, //Render X | |
0, //Render Y | |
0.5 //Ratio | |
); */ | |
for (int i=0; i<=5; i++) | |
{ | |
for (int j=0; j<=5; j++) | |
{ | |
this.renderEstrela( | |
g, //Objeto Graphics | |
Color.WHITE, //Cor | |
(i*40), //Render X | |
(j*45), //Render Y | |
0.3 //Ratio | |
); | |
} | |
} | |
} | |
/** | |
* Calcula o tamanho da porcentagem dado dimensões do objeto Panel | |
* @param Axis | |
* @param percent | |
* @return | |
*/ | |
private int getPercentSize(JPanel painel, char Axis, float percent) | |
{ | |
int painelWidth, painelHeight = 0; | |
//Coletando o tamanho do objeto | |
painelWidth = painel.getWidth(); | |
painelHeight = painel.getHeight(); | |
if (Axis == 'x') | |
return (int) (painelWidth * (percent / 100)); | |
else | |
if (Axis == 'y') | |
return (int) (painelHeight * (percent / 100)); | |
else | |
return 0; | |
} | |
private void botaoGenerateActionPerformed(java.awt.event.ActionEvent evt) { | |
this.renderBandeira(bandeira); | |
} | |
/** | |
* @param args the command line arguments | |
*/ | |
public static void main(String args[]) { | |
/* Set the Nimbus look and feel */ | |
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> | |
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. | |
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html | |
*/ | |
try { | |
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { | |
if ("Nimbus".equals(info.getName())) { | |
javax.swing.UIManager.setLookAndFeel(info.getClassName()); | |
break; | |
} | |
} | |
} catch (ClassNotFoundException ex) { | |
java.util.logging.Logger.getLogger(GLSdoSul.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (InstantiationException ex) { | |
java.util.logging.Logger.getLogger(GLSdoSul.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (IllegalAccessException ex) { | |
java.util.logging.Logger.getLogger(GLSdoSul.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} catch (javax.swing.UnsupportedLookAndFeelException ex) { | |
java.util.logging.Logger.getLogger(GLSdoSul.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); | |
} | |
//</editor-fold> | |
/* Create and display the form */ | |
java.awt.EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
new GLSdoSul().setVisible(true); | |
} | |
}); | |
} | |
// Variables declaration - do not modify | |
private javax.swing.JPanel bandeira; | |
private javax.swing.JButton botaoGenerate; | |
private javax.swing.JLabel jLabel1; | |
// End of variables declaration | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment