ola Programadores do GUJ!!!
venho até voces para obter ajuda estou com um código que faz o efeito matrix, aquele das letrinhas caindo… bom o código está quase todo bem a não ser por uma linha que esta em vermelho. é esta linha que está abaixo.
public class ExemploMatrix extends JFrame {
abaixo segue o código inteiro, gradeço a ajuda Obrigado e fiquem com DEUS.
/*
- matrix.java
- Created on 28 de Julho de 2013, 17:56
*/
package guj;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
public class ExemploMatrix extends JFrame {
private JTextArea textArea;
private Timer timer;
/**//**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ExemploMatrix frame = new ExemploMatrix();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ExemploMatrix() {
initComponents();
}
char[] matrix = "?????? ????????? ???? ???????????? ? ??????????????".toCharArray();
int step;
Random r = new Random();
public void showMatrixEffect() {
FontMetrics fm = getTextArea().getFontMetrics(getTextArea().getFont());
int starWidth = SwingUtilities.computeStringWidth(fm, "*");
int nColumns = getWidth() / starWidth;
int nRows = getHeight() / fm.getHeight();
StringBuilder sbText = new StringBuilder();
for (int r = 0; r < nRows; ++r) {
for (int c = 0; c < nColumns; ++c) {
sbText.append(matrix[(step + r + c * nRows) % matrix.length]);
}
sbText.append("\n");
}
getTextArea().setText(sbText.toString());
step = r.nextInt(100);
}
private void initComponents() {
setBounds(100, 100, 450, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
getContentPane().add(getTextArea(), BorderLayout.CENTER);
getTimer().start();
}
private JTextArea getTextArea() {
if (textArea == null) {
textArea = new JTextArea();
textArea.setForeground(Color.GREEN);
textArea.setBackground(Color.BLACK);
textArea.setEditable(false);
textArea.setFont(new Font("Monospaced", Font.BOLD, 12));
}
return textArea;
}
private Timer getTimer() {
if (timer == null) {
timer = new Timer(100, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showMatrixEffect();
}
});
}
return timer;
}
}
/**
*
-
@author Junior
*/
public class matrix extends javax.swing.JFrame {/** Creates new form matrix */ public matrix() { 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() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) );
pack();
}//
/**
-
@param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new matrix().setVisible(true);
}
});
}
// Variables declaration - do not modify
// End of variables declaration -