Fórum Trocar a imagem quando clicar no botão #568974
21/10/2010
0
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
//criar um novo metodo, usando ImageButton;
public class BotaoComando extends JFrame implements ActionListener {
JButton botaoComando;
String pedindoComando = "@@@,a?,&";
char[] comandoChar = pedindoComando.toCharArray();
int[] comandoInteiro = new int[comandoChar.length];
JLabel label;
DriverSerial driver;// = new DriverSerial ("comandoInteiro");
public BotaoComando()
{
super(" Controle ");
Container tela = getContentPane();
tela.setLayout(null);
botaoComando = new JButton ("Controle TV");
botaoComando.setBounds(180, 30, 100, 40);
ImageIcon img = (new ImageIcon("C:/Katarina/Controle/controle.jpg"));
if(img == null)
{
System.out.println("erro");
}
label = new JLabel(img);
label.setBounds(80,80,290,290);
tela.add(botaoComando);
tela.add(label);
this.setSize(600,440);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
botaoComando.addActionListener((ActionListener) this);
botaoComando.setToolTipText("Clique neste botão "
+ "para usar o controle.");
driver = new DriverSerial("Controle TV");
driver.open();
}
private boolean ImageIcon(String string) {
// TODO Auto-generated method stub
return false;
}
public void actionPerformed(ActionEvent e)
{
for (int cont = 0; cont >= comandoInteiro.length; cont++)
{
System.out.println (comandoInteiro[0]);
}
//System.out.println("Testando código");
driver.sendBytes(comandoInteiro);
}
public static void main(String args[])
{
new BotaoComando();
}
}Katarina
Curtir tópico
+ 0Posts
21/10/2010
Thales Barbosa
Gostei + 0
21/10/2010
Thales Barbosa
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source) at BotaoComando.actionPerformed(BotaoComando.java:66) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
Gostei + 0
21/10/2010
Thales Barbosa
Gostei + 0
21/10/2010
Thales Barbosa
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
//criar um novo metodo, usando ImageButton;
public class BotaoComando extends JFrame implements ActionListener {
JButton botaoComando;
String pedindoComando = "@@@,a?,&";
char[] comandoChar = pedindoComando.toCharArray();
int[] comandoInteiro = new int[comandoChar.length];
JLabel label;
DriverSerial driver;// = new DriverSerial ("comandoInteiro");
public BotaoComando()
{
super(" Controle ");
Container tela = getContentPane();
tela.setLayout(null);
botaoComando = new JButton ("Controle TV");
botaoComando.setBounds(180, 30, 100, 40);
ImageIcon img = (new ImageIcon("C:/Katarina/Controle/controle.jpg"));
if(img == null)
{
System.out.println("erro");
}
label = new JLabel(img);
label.setBounds(80,80,290,290);
tela.add(botaoComando);
tela.add(label);
this.setSize(600,440);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
botaoComando.addActionListener((ActionListener) this);
botaoComando.setToolTipText("Clique neste botão "
+ "para usar o controle.");
driver = new DriverSerial("Controle TV");
driver.open();
}
private boolean ImageIcon(String string) {
// TODO Auto-generated method stub
return false;
}
public void actionPerformed(ActionEvent e)
{
JLabel Jlabel = null;
Jlabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("C:/Katarina/Controle/ctr.jpg")));
// botaoComando.setActionCommand("C:/Katarina/Controle/ctr.jpg");
for (int cont = 0; cont >= comandoInteiro.length; cont++)
{
System.out.println (comandoInteiro[0]);
}
//System.out.println("Testando código");
driver.sendBytes(comandoInteiro);
}
public static void main(String args[])
{
new BotaoComando();
}
}
Gostei + 0
21/10/2010
Thales Barbosa
Gostei + 0
22/10/2010
Thales Barbosa
Gostei + 0
22/10/2010
Thales Barbosa
Gostei + 0
22/10/2010
Thales Barbosa
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
//criar um novo metodo, usando ImageButton;
public class BotaoComando extends JFrame implements ActionListener {
JButton botaoComando;
String pedindoComando = "@@@,a?,&";
char[] comandoChar = pedindoComando.toCharArray();
int[] comandoInteiro = new int[comandoChar.length];
JLabel label;
String name = "C:/Katarina/Controle/ctr.jpg";
ImageIcon img = new ImageIcon(getClass().getResource("C:/Katarina/Controle/controle.jpg"));
ImageIcon img2 = new ImageIcon(getClass().getResource("C:/Katarina/Controle/ctr.jpg"));
DriverSerial driver;// = new DriverSerial ("comandoInteiro");
public BotaoComando() {
super(" Controle ");
Container tela = getContentPane();
tela.setLayout(null);
botaoComando = new JButton("Controle TV");
botaoComando.setBounds(180, 30, 100, 40);
//ImageIcon img = new ImageIcon("C:/Katarina/Controle/controle.jpg");
//ImageIcon img2 = new ImageIcon(getClass().getResource("C:/Katarina/Controle/ctr.jpg"));
//ImageIcon img = new ImageIcon(getClass().getResource("C:/Katarina/Controle/ctr.jpg"));
//ImageIcon img = new ImageIcon(Menu.class.getResource("C:/Katarina/Controle/ctr.jpg"));
if (img == null) {
System.out.println("erro");
}
label = new JLabel(img);
label.setBounds(80, 80, 290, 290);
tela.add(botaoComando);
tela.add(label);
this.setSize(600, 440);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
botaoComando.addActionListener(this);
botaoComando.setToolTipText("Clique neste botão "
+ "para usar o controle.");
driver = new DriverSerial("Controle TV");
driver.open();
}
private boolean ImageIcon(String string) {
// TODO Auto-generated method stub
return false;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == this.botaoComando){
System.out.println("Apertado");
botaoComando.setActionCommand(name);
botaoComando.setIcon(img2);
}
else
System.out.println("Apertado2");
// JLabel Jlabel = null;
// Jlabel.setIcon(new javax.swing.ImageIcon(getClass().getResource(
// "C:/Katarina/Controle/ctr.jpg")));
for (int cont = 0; cont >= comandoInteiro.length; cont++)
System.out.println(comandoInteiro[0]);
}
public static void main(String args[]) {
new BotaoComando();
}
}
Gostei + 0
22/10/2010
Thales Barbosa
Gostei + 0
22/10/2010
Thales Barbosa
Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
...
...
ImageIcon img = new ImageIcon(getClass().getResource("controle.jpg"));
...Gostei + 0
26/10/2010
Thales Barbosa
Gostei + 0
26/10/2010
Thales Barbosa
Gostei + 0
27/10/2010
Thales Barbosa
Gostei + 0
28/10/2010
Thales Barbosa
Gostei + 0