Bom Dia,
Por favor, alguém pode me ajudar a identificar o erro?
Tenho duas classes "StandardFrame" e "MainFrame" onde a 1ª define meu padrão de janela e na 2ª eu crio a janela principal. na classe StandardFrame estou tendo o erro "
Seguem os códigos:
package projectone;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.border.*;
import java.text.DecimalFormat;
public class StandardFrame extends JFrame {
JLabel hours, date;
String dayweek[] = {"Domingo", "2ª Feira", "3ª Feira", "4ª Feira", "5ª Feira", "6ª Feira", "Sábado"};
String month[] = {"Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"};
JTextField status;
protected int width = 1025, hight = 750;
protected String title = "Sem Título";
protected String icon = "Padrão";
protected boolean resizable = true;
protected String mode = "Normal";
public void show() {
Container standardwindow = getContentPane();
standardwindow.setLayout(null);
this.setSize(width, hight);
this.setTitle(title);
if(icon != "Padrão") {
ImageIcon iconimg = new ImageIcon(icon);
setIconImage(iconimg.getImage());
}
this.setResizable(resizable);
this.setVisible(true);
if(mode == "Normal")
setExtendedState(NORMAL);
else if(mode == "Iconified")
setExtendedState(ICONIFIED);
else
setExtendedState(MAXIMIZED_BOTH);
}
// -------------------------------------------------------------------------
// Painel Inferior
Border border = BorderFactory.createLoweredBevelBorder();
status = new JTextField(JTextField.CENTER);
status.setPreferredSize(new Dimension(720, 20));
status.setFont(new Font("Arial", Font.BOLD, 12));
status.setEditable(false);
status.setBorder(border);
hours = new JLabel("horas", JLabel.CENTER);
hours.setPreferredSize(new Dimension(75, 20));
hours.setBorder(border);
date = new JLabel("data", JLabel.CENTER);
date.setPreferredSize(new Dimension(215, 20));
date.setBorder(border);
JPanel bottonpanel = new JPanel();
bottonpanel.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 0));
bottonpanel.add(status);
bottonpanel.add(hours);
bottonpanel.add(date);
BorderLayout lobp = new BorderLayout();
standardwindow.setLayout(lobp);
standardwindow.add(bottonpanel, BorderLayout.SOUTH);
// -------------------------------------------------------------------------
// Atualização da Data e do Relógio
ActionListener task = new ActionListener() {
public void actionPerformed(ActionEvent e) {
hoursDate();
}
};
javax.swing.Timer timer = new javax.swing.Timer(1000, task);
timer.start();
// -------------------------------------------------------------------------
// Funcionamento da Data e do Relógio
private void hoursDate() {
Calendar now = Calendar.getInstance();
int ho = now.get(Calendar.HOUR_OF_DAY);
int mi = now.get(Calendar.MINUTE);
int se = now.get(Calendar.SECOND);
int dw = now.get(Calendar.DAY_OF_WEEK);
int dy = now.get(Calendar.DAY_OF_MONTH);
int mt = now.get(Calendar.MONTH);
int yr = now.get(Calendar.YEAR);
hours.setText(format(ho % 24) + ":" + format(mi) + ":" + format(se) + "");
date.setText(dayweek[dw - 1] + ", " + format(dy) + " de " + month[mt] + " de " + yr + "");
}
private String format(int num) {
DecimalFormat df = new DecimalFormat("00");
return df.format(num);
}
}
package projectone;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MainFrame extends StandardFrame {
JMenuItem files, sales, optns, accnt, invcn, exit, about;
Password wndw;
String user = "fabiano", password = "102010";
public MainFrame() {
title = "Power Freight";
hight = 750;
width = 1025;
resizable = true;
icon = "Padrão";
mode = "Maximized";
show();
Container mainwindow = getContentPane();
mainwindow.setLayout(null);
// -------------------------------------------------------------------------
// Preparação do MainFrame para Solicitação de Usuário e Senha
wndw = new Password(null, "Nome do Usuário e Senha", true);
wndw.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
wndw.setVisible(true);
// -------------------------------------------------------------------------
// Menu
// Barra de Menus
JMenuBar bar = new JMenuBar();
setJMenuBar(bar);
// Item do Menu
JMenu movements = new JMenu("Movimentos");
movements.setMnemonic(KeyEvent.VK_A);
JMenu help = new JMenu("Ajuda");
help.setMnemonic(KeyEvent.VK_J);
// SubItens do Menu
Treatment treat = new Treatment();
exit = new JMenuItem("Sair");
exit.setMnemonic(KeyEvent.VK_S);
exit.addActionListener(treat);
files = new JMenuItem("Cadastros");
files.setMnemonic(KeyEvent.VK_C);
files.addActionListener(treat);
sales = new JMenuItem("Comercial");
sales.setMnemonic(KeyEvent.VK_M);
sales.addActionListener(treat);
optns = new JMenuItem("Operações");
optns.setMnemonic(KeyEvent.VK_O);
optns.addActionListener(treat);
accnt = new JMenuItem("Financeiro");
accnt.setMnemonic(KeyEvent.VK_F);
accnt.addActionListener(treat);
invcn = new JMenuItem("Faturamento");
invcn.setMnemonic(KeyEvent.VK_T);
invcn.addActionListener(treat);
about = new JMenuItem("Sobre o Power Freight");
about.setMnemonic(KeyEvent.VK_P);
about.addActionListener(treat);
// Adiciona SubItens aos Itens
movements.add(files);
movements.add(sales);
movements.add(optns);
movements.add(accnt);
movements.add(invcn);
movements.addSeparator();
movements.add(exit);
help.add(about);
// Adiciona Itens à Barra
bar.add(movements);
bar.add(help);
// -------------------------------------------------------------------------
// Componentes
JButton btnone = new JButton("Botão 1");
btnone.setBounds(95, 95, 100, 100);
mainwindow.add(btnone);
}
// -------------------------------------------------------------------------
// Método main()
public static void main(String args[]) {
final MainFrame app = new MainFrame();
app.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
app.addWindowListener(
new WindowAdapter() {
public void windowClosing(WindowEvent e) {
Object[] Btns = {" Sim ", " Não "};
int confirmexit = JOptionPane.showOptionDialog(null, "Deseja mesmo encerrar o Power Freight?", "Sair", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Btns, Btns[1]);
if(confirmexit == 0)
System.exit(0);
}
}
);
};
// -------------------------------------------------------------------------
// Janela de Solicitação e Averiguação de Usuário e Senha
public void verify(String u, String p) {
if((u.equals(user)) && (p.equals(password)))
wndw.hide();
else {
JOptionPane.showMessageDialog(null, "Usuário e/ou Senha Incorretos");
wndw.txtUser.requestFocus();
}
}
private class Password extends JDialog {
JTextField txtUser;
JPasswordField txtPassword;
JButton enter, cancel;
public Password(Frame owner, String title, boolean modal) {
super(owner, title, modal);
Container mainwindow = getContentPane();
BorderLayout layout = new BorderLayout();
mainwindow.setLayout(layout);
JLabel lblUser = new JLabel("Nome do Usuário:");
JLabel lblPassword = new JLabel("Senha:");
txtUser = new JTextField(10);
txtPassword = new JPasswordField(10);
JPanel upper = new JPanel();
upper.setLayout(new GridLayout(2, 2, 5, 5));
upper.add(lblUser);
upper.add(txtUser);
upper.add(lblPassword);
upper.add(txtPassword);
JPanel upper2 = new JPanel();
String ttl = "Informe o Nome do Usuário e Senha";
Border etched = BorderFactory.createEtchedBorder();
Border border = BorderFactory.createTitledBorder(etched, ttl);
upper2.setBorder(border);
upper2.setLayout(new FlowLayout(FlowLayout.LEFT));
upper2.add(upper);
TreatUsPsw treat0 = new TreatUsPsw();
enter = new JButton("Entrar");
enter.addActionListener(treat0);
getRootPane().setDefaultButton(enter);
cancel = new JButton("Cancelar");
cancel.addActionListener(treat0);
JPanel lower = new JPanel();
lower.setLayout(new FlowLayout(FlowLayout.RIGHT));
lower.add(enter);
lower.add(cancel);
mainwindow.add(BorderLayout.NORTH, upper2);
mainwindow.add(BorderLayout.SOUTH, lower);
setSize(280, 150);
setLocationRelativeTo(null);
}
private class TreatUsPsw implements ActionListener {
public void actionPerformed(ActionEvent e) {
String password = new String(txtPassword.getPassword());
// Teste Ususário e Senha
if (e.getSource() == enter) {
verify(txtUser.getText(), password);
}
else
System.exit(0);
}
}
}
// -------------------------------------------------------------------------
// Tratamento de Eventos do MainFrame
private class Treatment implements ActionListener {
public void actionPerformed(ActionEvent e) {
// Saída do Sistema
if(e.getSource() == exit) {
Object Butns[] = {" Sim ", "Não"};
int closing = JOptionPane.showOptionDialog(null, "Deseja mesmo encerrar o Power Freight?", "Sair", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, Butns, Butns[1]);
if(closing == 0)
System.exit(0);
}
// Indicacao na Barra de Status
else if (e.getSource() instanceof JMenuItem) {
JMenuItem mi = (JMenuItem) e.getSource();
status.setText(mi.getText());
}
}
}
}
Muito Obrigado!
ffranco