package Interface;
import iconspanel.IconPanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.SimpleTimeZone;
import java.util.TimeZone;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.border.EtchedBorder;
import util.AtualizadorHorario;
import util.ClienteUtils;
import com.swtdesigner.SwingResourceManager;
public class Principal extends JFrame {
private static final long serialVersionUID = 1L;
private IconPanel iconsPanel;
private JLabel msgLabel;
private JMenuBar menuBar;
private Timer timerLetreiro;
private JLabel dataHoraLabel;
private static Principal principal;
class ActionListenerLetreiro implements ActionListener {
public void actionPerformed(ActionEvent e) {
if ((msgLabel.getX() + msgLabel.getWidth()) > 1) {
msgLabel.setLocation(msgLabel.getX() - 1, msgLabel.getY());
} else {
msgLabel.setLocation(getWidth(), msgLabel.getY());
}
}
}
private void iniciarLetreiro() {
timerLetreiro = new Timer(15, new ActionListenerLetreiro());
timerLetreiro.start();
}
public static void main(String args[]) {
SimpleTimeZone timezone = new SimpleTimeZone(-4 * 60 * 60 * 1000, "Brazil/West");
TimeZone.setDefault(timezone);
principal = new Principal();
principal.setVisible(true);
}
/**
* Create the frame
*/
public Principal() {
super();
setIconImage(SwingResourceManager.getImage(Principal.class, "/Img/icone2.gif"));
//setIconImage(SwingResourceManager.getImage(Principal.class, "/resource/images/IconeFaturamento.png"));
setTitle("Escala - Educação Musical");
getContentPane().setLayout(new BorderLayout());
setBounds(100, 100, 800, 600);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int opt = JOptionPane.showConfirmDialog((Window) e.getSource(), "Confirma sair do sistema?", "Confirmação", JOptionPane.YES_NO_OPTION);
if (opt == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
public void windowOpened(final WindowEvent e) {
}
});
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (InstantiationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IllegalAccessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (UnsupportedLookAndFeelException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
setSize(new Dimension(800, 600));
setLocationRelativeTo(null);
customInit();
final JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1, 0));
panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED));
panel.setPreferredSize(new Dimension(0, 40));
panel.setMaximumSize(new Dimension(0, 40));
panel.setMinimumSize(new Dimension(0, 40));
getContentPane().add(panel, BorderLayout.SOUTH);
final JPanel panel_1 = new JPanel();
panel_1.setLayout(null);
panel.add(panel_1);
msgLabel = new JLabel();
msgLabel.setFont(new Font("", Font.PLAIN, 14));
msgLabel.setBounds(562, 18, 226, 18);
msgLabel.setForeground(new Color(0, 0, 255));
msgLabel.setText("ESCALA - Educação Musical");
panel_1.add(msgLabel);
final JLabel label = new JLabel();
label.setBounds(0, 0, 40, 18);
panel_1.add(label);
label.setForeground(Color.RED);
label.setText("Usuário:");
final JLabel administradorLabel = new JLabel();
administradorLabel.setBounds(45, 0, 94, 18);
panel_1.add(administradorLabel);
administradorLabel.setForeground(Color.RED);
administradorLabel.setText("Administrador");
dataHoraLabel = new JLabel();
dataHoraLabel.setBounds(530, -2, 171, 18);
panel_1.add(dataHoraLabel);
dataHoraLabel.setHorizontalTextPosition(SwingConstants.RIGHT);
dataHoraLabel.setHorizontalAlignment(SwingConstants.RIGHT);
dataHoraLabel.setFont(new Font("", Font.BOLD, 14));
menuBar = new JMenuBar();
setJMenuBar(menuBar);
final JMenu sistemaMenu = new JMenu();
sistemaMenu.setText("Sistema");
menuBar.add(sistemaMenu);
final JMenuItem menuItem = new JMenuItem();
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
}
});
menuItem.setText("Horários de Aula");
sistemaMenu.add(menuItem);
sistemaMenu.addSeparator();
final JMenuItem sairMenuItem = new JMenuItem();
sairMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
int opt = JOptionPane.showConfirmDialog(null, "Confirma sair do sistema?", "Confirmação", JOptionPane.YES_NO_OPTION);
if (opt == JOptionPane.YES_OPTION) {
System.exit(0);
}
}
});
sairMenuItem.setText("Sair");
sistemaMenu.add(sairMenuItem);
final JMenu alunosMenu = new JMenu();
alunosMenu.setText("Alunos");
menuBar.add(alunosMenu);
final JMenuItem cadastrarAlunoMenuItem = new JMenuItem();
cadastrarAlunoMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
CadastroAlunoSwing tela = new CadastroAlunoSwing();
tela.setModal(true);
tela.setResizable(false);
tela.setVisible(true);
}
});
cadastrarAlunoMenuItem.setText("Cadastrar Aluno");
alunosMenu.add(cadastrarAlunoMenuItem);
final JMenu professoresMenu = new JMenu();
professoresMenu.setText("Professores");
menuBar.add(professoresMenu);
final JMenuItem cadastrarProfessoresMenuItem = new JMenuItem();
cadastrarProfessoresMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
CadastroProfessorSwing tela = new CadastroProfessorSwing();
tela.setModal(true);
tela.setResizable(false);
tela.setVisible(true);
}
});
cadastrarProfessoresMenuItem.setText("Cadastrar Professor");
professoresMenu.add(cadastrarProfessoresMenuItem);
final JMenu financeiroMenu = new JMenu();
financeiroMenu.setText("Financeiro");
menuBar.add(financeiroMenu);
final JMenuItem menuItem_1 = new JMenuItem();
menuItem_1.setText("???");
financeiroMenu.add(menuItem_1);
final JMenu partiturasMenu = new JMenu();
partiturasMenu.setText("Partituras");
menuBar.add(partiturasMenu);
final JMenuItem cadastrarPartituraMenuItem = new JMenuItem();
cadastrarPartituraMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
CadastroPartituraSwing tela = new CadastroPartituraSwing();
tela.setModal(true);
tela.setResizable(false);
tela.setVisible(true);
}
});
cadastrarPartituraMenuItem.setText("Cadastrar Partitura");
partiturasMenu.add(cadastrarPartituraMenuItem);
final JMenuItem emprestarPartituraMenuItem = new JMenuItem();
emprestarPartituraMenuItem.setText("Emprestar Partitura");
partiturasMenu.add(emprestarPartituraMenuItem);
final JMenuItem buscarPartiturasMenuItem = new JMenuItem();
buscarPartiturasMenuItem.setText("Buscar Partituras");
partiturasMenu.add(buscarPartiturasMenuItem);
final JMenu menu_1 = new JMenu();
menu_1.setText("Relatórios");
menuBar.add(menu_1);
final JMenuItem alunosMenuItem = new JMenuItem();
alunosMenuItem.setText("Alunos");
menu_1.add(alunosMenuItem);
final JMenuItem menuItem_2 = new JMenuItem();
menuItem_2.setText("Pendências Financeiras de Alunos");
menu_1.add(menuItem_2);
final JMenuItem partiturasEmprestadasMenuItem = new JMenuItem();
partiturasEmprestadasMenuItem.setText("Partituras Emprestadas");
menu_1.add(partiturasEmprestadasMenuItem);
mostrarHora();
}
private void customInit() {
// **** Define localização componenetes dos JOptionPane's e FileChooser
// **** //
ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
//UIManager.put("OptionPane.yesButtonText", "Sim");
UIManager.put("OptionPane.yesButtonText", bundle.getString("Yes"));
UIManager.put("OptionPane.yesButtonText", bundle.getString("Yes"));
UIManager.put("OptionPane.noButtonText", bundle.getString("No"));
UIManager.put("OptionPane.cancelButtonText", bundle.getString("Cancel"));
UIManager.put("FileChooser.openButtonText", bundle.getString("Open"));
UIManager.put("FileChooser.cancelButtonText", bundle.getString("Cancel"));
UIManager.put("FileChooser.title", bundle.getString("Title"));
UIManager.put("FileChooser.lookInLabelText", bundle.getString("LookInLabelText"));
UIManager.put("FileChooser.filesOfTypeLabelText", bundle.getString("FilesOfTypeLabelText"));
UIManager.put("FileChooser.upFolderToolTipText", bundle.getString("UpFolderToolTipText"));
UIManager.put("FileChooser.fileNameLabelText", bundle.getString("FileNameLabelText"));
// *************************************************************************
initIcons();
setExtendedState(JFrame.MAXIMIZED_BOTH);
iniciarLetreiro();
}
private void initIcons() {
// Applications Icons.
ImageIcon backImage = new ImageIcon(Principal.class.getResource("/Img/Fundo.jpg"));
iconsPanel = new IconPanel(backImage);
iconsPanel.setBackground(Color.WHITE);
getContentPane().add(iconsPanel, BorderLayout.CENTER);
}
public void mostrarHora() {
AtualizadorHorario ah = new AtualizadorHorario(dataHoraLabel);
ah.mostrarData(true);
Thread thHora = ah;
thHora.start();
}
}
Tenho esse código acima, que é a janela principal de um sisteminha. eu tenho um label chamado dataHoraLabel que eu quero que fique sempre do lado direito inferior, dentro do panel_1, a tela é feita em 800x600, porém quando eu maximizo eu e consequentemente o panel_1 aumenta, o relógio não acompanha indo para o lado direito, ele mantem a posição q era e acaba ficando no meio do label. heheh
e agora ?? huAEhA