Bom dia Galera!
Estou tentando colocar uma imagem no lado direito da tela.Já tentei de diversas formas e nao consigo.
A imagem está dentro do meu pacote.
Vou postar meu código se alguem puder me ajudar vou ficar muito grata.
Obrigada.
[code]package br.teste;
import java.awt.Color;
import java.awt.Image;
import java.awt.Toolkit;
import javax.imageio.ImageIO;
import javax.swing.BorderFactory;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JLabel;
import javax.swing.JTextField;
import br.com.bradseg.webtran.recursos.Constantes;
import br.com.bradseg.webtran.view.recursos.campos.Campos;
import javax.swing.JPasswordField;
public class Principal extends JFrame implements ActionListener{
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JLabel jLabel = null;
private JLabel jLabel1 = null;
private JLabel jLabel2 = null;
private JLabel jLabel3 = null;
private JLabel jLabelLogoMarca = new JLabel();
public static final Color COLOR = new Color(Constantes.NUM_225, Constantes.NUM_45, Constantes.NUM_45); // @jve:decl-index=0:
private JPasswordField jPasswordField = null;
private JTextField jTextField = null;
private JButton jButton;
private JLabel jLabel4 = null;
private JLabel jLabel5 = null;
private JLabel jLabel6 = null;
private JButton jButton1 = null;
private JLabel jLabel7 = null;
public Principal() throws IOException {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(1024, 668);
this.setContentPane(getJContentPane());
this.setTitle("Bradesco Seguros e Previdência");
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel7 = new JLabel();
jLabel7.setBounds(new Rectangle(7, 295, 119, 25));
jLabel7.setText(":: Mais informações");
jLabel6 = new JLabel();
jLabel6.setBounds(new Rectangle(21, 220, 221, 27));
jLabel6.setText("Acesse com seu Certificado Digital");
jLabel5 = new JLabel();
jLabel5.setBounds(new Rectangle(5, 194, 154, 23));
jLabel5.setText(":: Não possuo senha");
jLabel4 = new JLabel();
jLabel4.setBounds(new Rectangle(7, 168, 153, 23));
jLabel4.setText("::Esqueci minha senha");
jLabel3 = new JLabel();
jLabel3.setBounds(new Rectangle(8, 27, 237, 16));
jLabel3.setText("com a Bradesco Seguros e Previdência");
jLabel2 = new JLabel();
jLabel2.setBounds(new Rectangle(48, 1, 141, 24));
jLabel2.setText("JÁ TRABALHO");
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(6, 64, 151, 16));
jLabel1.setText("CPF ou CNPJ ou MATRIZ:");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(5, 113, 67, 16));
jLabel.setText("SENHA:");
jContentPane = new JPanel();
jContentPane.setBorder(BorderFactory.createTitledBorder(""));
jContentPane.setLayout(null);
jContentPane.add(jLabel, null);
jContentPane.add(jLabel1, null);
jContentPane.add(jLabel2, null);
jContentPane.add(jLabel3, null);
jContentPane.add(getJPasswordField(), null);
jContentPane.add(getJTextField(), null);
jContentPane.add(getJButton(), null);
jContentPane.add(jLabel4, null);
jContentPane.add(jLabel5, null);
jContentPane.add(jLabel6, null);
jContentPane.add(getJButton1(), null);
jContentPane.add(jLabel7, null);
jLabel2.setFont(new java.awt.Font("Times New Roman", 1, 18));
jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 12));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel.setFont(new java.awt.Font("Times New Roman", 1, 12));
jLabel.setForeground(new java.awt.Color(255, 255, 255)); //cor branca
jLabel6.setForeground(new java.awt.Color(255, 255, 255)); //cor branca
jLabel2.setForeground(new java.awt.Color(255, 255, 255)); //cor branca
jLabel3.setForeground(new java.awt.Color(255, 255, 255)); //cor branca
jLabel5.setForeground(new java.awt.Color(255, 0, 0)); //cor vermelha
jLabel4.setForeground(new java.awt.Color(255, 0, 0));
jLabel7.setForeground(new java.awt.Color(255, 0, 0));
// centraliza a janela
setLocationRelativeTo(null);
// Evita que a JFrame seja redimensionada
this.setResizable(false);
// Define a cor de fundo
jContentPane.setBackground(Color.GRAY);
this.setSize(350, 250);
setVisible(true);
jLabelLogoMarca.setOpaque(true);
}
return jContentPane;
}
public void actionPerformed(ActionEvent ae)
{
String value1=jTextField.getText();
String value2=jPasswordField.getText();
if (value1.equals("stefanini") && value2.equals("stefanini")) {
NextPage page=new NextPage();
page.setVisible(true);
limpaCampos();
}
else{
limpaCampos();
JOptionPane.showMessageDialog(this,"Entre com uma Login e Senha válidos!","Erro",JOptionPane.ERROR_MESSAGE);
}
}
private void limpaCampos(){
jTextField.setText("");
jPasswordField.setText("");
}
/**
-
This method initializes jPasswordField
-
@return javax.swing.JPasswordField
*/
private JPasswordField getJPasswordField() {
if (jPasswordField == null) {
jPasswordField = new JPasswordField();
jPasswordField.setBounds(new Rectangle(4, 139, 86, 20));
}
return jPasswordField;
}/**
- This method initializes jTextField
-
@return javax.swing.JTextField
*/
private JTextField getJTextField() {
if (jTextField == null) {
jTextField = new JTextField();
jTextField.setBounds(new Rectangle(4, 85, 184, 20));
}
return jTextField;
}
/**
- This method initializes jButton
-
@return javax.swing.JButton
*/
private JButton getJButton() {
if (jButton == null) {
jButton = new JButton();
jButton.setBounds(new Rectangle(95, 138, 56, 22));
jButton.setText(“OK”);
jButton.addActionListener(this);
}
return jButton;
}
/**
- This method initializes jButton1
-
@return javax.swing.JButton
*/
private JButton getJButton1() {
if (jButton1 == null) {
jButton1 = new JButton();
jButton1.setBounds(new Rectangle(6, 250, 240, 34));
jButton1.setText(“Certificado Digital”);
}
return jButton1;
}
public static void main(String arg[])
{
try
{
Principal frame=new Principal();
frame.setSize(800,400);
frame.setBackground(getColor());
frame.setVisible(true);
frame.setIconImage(ImageIO.read(frame.getClass().getResource(Campos.IMG_ICON)));//imagem Image i = Toolkit.getDefaultToolkit().getImage(frame.getClass().getResource(Campos.IMG_LOGOMARCA)); frame.setImageIcon(i); }catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}private void setImageIcon(Image i) {
// TODO Auto-generated method stub}
public JLabel getJLabelLogoMarca() {
return jLabelLogoMarca;
}public static Color getColor() { return COLOR; }
}[/code]