LG11
Janeiro 14, 2008, 3:19pm
#1
gente… tenhu um programa e quero poder habilitar mapa nele… so que…
tenhu um JFrame de (500, 500)…
Gostaria de fazer pra quando a pessoa ativar o “JCheckBoxMenuItem”… um Frame aparecer do lado direito do meu frame. Exatamente com proporção 50 pixels menor que o original.
mas o frame n pode ser movido. ele tem q ser grudado com o frame original.
Exemplo…
o Nero 7 “StartSmart” tem essa ferramenta… so que é uma setinha no canto esquerdo da tela dele… quero fazer algo parecido.
Mas não sei como.
LG11
Janeiro 18, 2008, 3:05pm
#2
ninguem… poxa…
deve ser algo mto complicado de se fazer.
t_java
Janeiro 18, 2008, 3:20pm
#3
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JanelaPrincipal extends JFrame {
private JanelaMapa mapa;
private Point coordenada;
private Dimension tamanho;
private boolean executar = false;
private boolean processo = false;
private boolean exibido = true;
private JButton cmdexibir;
public JanelaPrincipal() {
super();
setSize(500,500);
setLayout(null);
mapa = new JanelaMapa();
cmdexibir = new JButton("Esconder Mapa");
cmdexibir.setBounds(100,100,250,250);
getContentPane().add(cmdexibir);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
mapa.setVisible(true);
moverJanelaMapa();
addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
if (exibido) {
moverJanelaMapa();
}
}
public void componentResized(ComponentEvent e){
if (exibido) {
redimensionarJanela();
}
}
});
addWindowListener(new WindowAdapter() {
public void windowActivated(WindowEvent e) {
if (exibido) {
if (executar) {
processo = true;
focarMapa();
}
}
}
public void windowDeactivated(WindowEvent e) {
if (exibido) {
if (!processo) {
executar = true;
}
processo = false;
}
}
public void windowClosed(WindowEvent e) {
mapa.dispose();
}
public void windowClosing(WindowEvent e) {
mapa.dispose();
}
});
mapa.addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
moverJanelaPrincipal();
}
});
cmdexibir.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (exibido) {
cmdexibir.setText("Mostrar Mapa");
exibido = false;
mapa.setVisible(false);
} else {
cmdexibir.setText("Esconder Mapa");
exibido = true;
mapa.setVisible(true);
moverJanelaPrincipal();
redimensionarJanela();
}
}
});
toFront();
}
private void moverJanelaMapa() {
coordenada = getLocation();
tamanho = getSize();
mapa.setLocation((int) (coordenada.getX()+tamanho.getWidth()),(int) (coordenada.getY()));
}
private void moverJanelaPrincipal() {
coordenada = mapa.getLocation();
tamanho = getSize();
setLocation((int) (coordenada.getX()-tamanho.getWidth()),(int) (coordenada.getY()));
}
private void redimensionarJanela(){
Dimension tela = Toolkit.getDefaultToolkit().getScreenSize();
tamanho = getSize();
if (tela.getWidth() < (tamanho.getWidth()+50)) {
tamanho.setSize((int) tamanho.getHeight(),(int) (tamanho.getWidth()-50));
setSize((int) tamanho.getHeight(),(int) tamanho.getWidth());
}
mapa.setSize(50,(int)tamanho.getHeight());
moverJanelaMapa();
}
private void focarMapa() {
executar = false;
mapa.toFront();
toFront();
}
public static void main(String[] args){
new JanelaPrincipal();
}
}
class JanelaMapa extends JDialog {
public JanelaMapa() {
super();
setSize(50,500);
setResizable(false);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
setLayout(new GridLayout(0,2));
getContentPane().add(new JLabel("Caixa 1"));
getContentPane().add(new JTextField());
getContentPane().add(new JLabel("Caixa 2"));
getContentPane().add(new JTextField());
getContentPane().add(new JLabel("Caixa 3"));
getContentPane().add(new JTextField());
getContentPane().add(new JButton("Opcao 1"));
getContentPane().add(new JButton("Opcao 2"));
getContentPane().add(new JButton("Opcao 3"));
getContentPane().add(new JButton("Opcao 4"));
getContentPane().add(new JButton("Opcao 5"));
getContentPane().add(new JButton("Opcao 6"));
}
}