Olá, boa noite.
Estou montando uma applet, no momento esla esta da seguinte forma.
public class SwingApplet extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1L;
JButton button;
public void init() {
// Force SwingApplet to come up in the System L&F
String laf = UIManager.getSystemLookAndFeelClassName();
try {
this.setLayout(null);
this.setBackground(Color.black);
UIManager.setLookAndFeel(laf);
} catch (UnsupportedLookAndFeelException exc) {
System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
} catch (Exception exc) {
System.err.println("Error loading " + laf + ": " + exc);
}
new principal(this).start();
}
}
Eu mando esta JApplet para um Thread que adciona os componentes.
public class principal extends Thread{
private JApplet applet;
private JButton jButton1 = new javax.swing.JButton();
private JButton jButton2 = new javax.swing.JButton();
private JButton jButton3 = new javax.swing.JButton();
private JLabel jLabel1 = new JLabel("Mastery");
private JPanel jPanel1 = new JPanel();
private String tipo;
public void setTipo(String tipo){
this.tipo = tipo;
}
public String getTipo(){
return this.tipo;
}
public principal(JApplet applet){
this.applet = applet;
}
public JPanel getJPanel1(){
return this.jPanel1;
}
public void removeJPanel(){
jPanel1.removeAll();
}
public void repaintAll(){
this.jPanel1.repaint();
this.applet.repaint();
}
public void run(){
jButton1.setToolTipText("Ver faltas - 'FLT'");
jButton1.setText("Base");
jButton1.setActionCommand("1");
jButton1.addActionListener(new Listener(this));
/*
jButton2.setToolTipText("Ver pedido - 'PT'");
jButton2.setText("P. Transferência");
jButton2.setActionCommand("2");
jButton2.addActionListener(new Listener(this));
jButton3.setToolTipText("Ver estoque OK - 'STK'");
jButton3.setText("Materiais OK");
jButton3.setActionCommand("3");
jButton3.addActionListener(new Listener(this));
jPanel1.setLayout(null);
jPanel1.setBackground(null);
jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
jLabel1.setFont(new Font("Arial", 1, 50));
//.addComponet(...)
Cada botão tem um evento, e oara cada evento ele abre componentes seing diferentes. E um dos eventos, ele carrega um outro JPanel painted com Graphics, O que me deixa realmente encabulado, é que no eclipse ele roda certinho mas no Browser ele congele o painel onde o painel com o desenho deveria ser adcionado.
Painel com o desenha
public class BarChart extends JPanel implements Runnable{
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel panel;
private Rectangle rectangle;
private ArrayList<matriz> dds;
public BarChart(JPanel panel,
int x, int y, int width, int height,
ArrayList<matriz> dds) {
this.panel = panel;
this.setLayout(null);
this.rectangle = new Rectangle(x, y, width, height);
this.dds = dds;
}
public void paint(Graphics g) {
g.setColor(Color.white);
g.fillRect(0, 0, this.getSize().width - 1, this.getSize().height - 1);
g.setColor(Color.BLACK);
g.drawLine(10, this.getSize().height - 20, this.getSize().width - 20, this.getSize().height - 20);
g.drawLine(20, 20, 20, this.getSize().height - 10);
if(true){
int a[] = {15, 20, 25};
int b[] = {30, 5, 30};
g.fillPolygon(getPolygon(a, b, 3));
}
if(true){
int v1 = this.getSize().width;
int v2 = this.getSize().height;
int a[] = {v1 - 20, v1 - 5, v1 - 20};
int b[] = {v2 - 25, v2 - 20, v2 - 15};
g.fillPolygon(getPolygon(a, b, 3));
}
if(true){
int x = this.getSize().width;
int y = this.getSize().height;
float max = dds.get(0).getQtd();
float col = (float) x / (float) dds.size() - 5;
int ix = 30;
for(int i = 0; i < dds.size(); i++){
float pg = (float)dds.get(i).getQtd() / max;
//System.out.println(y);
g.setColor(cor(i));
g.fillRect(ix, (int)((float)y - ((float)y * pg)+30), (int)col, (int)((float)y * pg)-49);
System.out.println((int)((float)y * pg)+60);
ix += (int)col + 5;
}
}
}
private Color cor(int i){
if(i == 0){return Color.blue;}
if(i == 1){return Color.cyan;}
if(i == 2){return Color.darkGray;}
if(i == 3){return Color.gray;}
if(i == 4){return Color.green;}
if(i == 5){return Color.lightGray;}
if(i == 6){return Color.magenta;}
if(i == 7){return Color.orange;}
if(i == 8){return Color.red;}
if(i == 9){return Color.yellow;}
if(i == 10){return Color.black;}
return Color.black;
}
private Polygon getPolygon(int[] xP, int[] yP, int lados){
return new Polygon(xP, yP, lados);
}
@Override
public void run() {
if(this.rectangle!=null){this.setBounds(this.rectangle);};
if(this.panel!=null){this.panel.add(this);this.panel.repaint();};
}
}
Estou realmente encafifado com isto