Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pokedex.view;
- import java.awt.*;
- import javax.swing.*;
- public class MainWindow extends Appearance {
- public MainWindow() {}
- public MainWindow(String windowTitle) {
- if(useSystemAppearance(this)) {
- initComponents(windowTitle);
- this.setVisible(true);
- }
- else System.out.println("Não foi possível usar a classe responsável pela aparência do SO");
- }
- private void initComponents(String windowTitle) {
- mainPanel = new JPanel();
- mainPanel.setBackground(Color.BLACK);
- this.setContentPane(mainPanel);
- this.setTitle(windowTitle);
- this.setSize(500, 700);
- this.setType(Type.UTILITY);
- this.setLayout(null);
- this.setResizable(false);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- // Painéis
- topPanel = new JPanel();
- topPanel.setBackground(new Color(0, 204, 102));
- topPanel.setLayout(null);
- topPanel.setBounds(0, 0, 500, 120);
- mainPanel.add(topPanel);
- contentPanel = new JPanel();
- contentPanel.setBackground(Color.WHITE);
- contentPanel.setLayout(null);
- contentPanel.setBounds(0, 120, 500, 600);
- mainPanel.add(contentPanel);
- actionPanel = new JPanel();
- actionPanel.setBackground(new Color(150, 150, 150));
- actionPanel.setLayout(null);
- actionPanel.setBounds(0, 340, 500, 50);
- contentPanel.add(actionPanel);
- // Botões
- for( int i = 0; i < MAXBUTTONS; i++ ) {
- button[i] = createDefaultButton(new JButton(buttonText[i]));
- if (i == 0) {
- button[i].setLocation(buttonY[i], buttonX[i]);
- topPanel.add(button[i]);
- }
- else {
- button[i].setLocation(buttonY[i], buttonX[i]);
- actionPanel.add(button[i]);
- }
- }
- comboBox = createDefaultComboBox(new JComboBox());
- comboBox.setLocation(120, 70);
- topPanel.add(comboBox);
- // textFields
- for( int i = 0; i < MAXTEXTFIELDS - 1; i++ ) { // o último pertence ao textArea
- textField[i] = createDefaultTextField(new JTextField(), textFieldText[i]);
- textField[i].setLocation(100, textFieldX[i]);
- contentPanel.add(textField[i]);
- }
- textArea = createDefaultTextArea(new JTextArea(), textFieldText[textFieldText.length - 1]);
- textArea.setLocation(100, textFieldX[textField.length]);
- contentPanel.add(textArea);
- //JScrollPane scroll = new JScrollPane();
- //scroll.add(textArea);
- confirmLabel = createDefaultConfirmJLabel(new JLabel("Confirmar Ação?"));
- confirmLabel.setBounds(180, 305, 200, 40);
- confirmLabel.setVisible(false);
- contentPanel.add(confirmLabel);
- setTextFieldName();
- }
- public JButton getButtonByIndex( int i ){
- return this.button[i];
- }
- public JTextField getTextFieldByIndex( int i ){
- return this.textField[i];
- }
- public JTextArea getTextArea() {
- return this.textArea;
- }
- public JComboBox getComboBox() {
- return this.comboBox;
- }
- public JPanel getContentPanel() {
- return contentPanel;
- }
- public JLabel getConfirmLabel() {
- return confirmLabel;
- }
- public void setConfirmLabel(JLabel confirmLabel) {
- this.confirmLabel = confirmLabel;
- }
- public JPanel getMainPanel() {
- return mainPanel;
- }
- public void setMainPanel(JPanel mainPanel) {
- this.mainPanel = mainPanel;
- }
- public JPanel getActionPanel() {
- return actionPanel;
- }
- public void setActionPanel(JPanel actionPanel) {
- this.actionPanel = actionPanel;
- }
- /**
- * Torna todos os textFields editáveis
- * @param state true = editavel
- */
- public void turnAllEditable(boolean state) {
- setTextAreaStatus(textArea, state);
- for (int i = 0; i < MAXTEXTFIELDS - 1; i++)
- setTextFieldStatus(textField[i], state);
- this.state = state;
- }
- /**
- * @return o estado atual dos textFields
- */
- public boolean getTextFieldStatus() {
- return this.state;
- }
- public void setTextFieldStatus(boolean state) {
- this.state = state;
- }
- /**
- * Deixa todos os TextFields com o valor definido no "name"
- */
- public void setTextFieldName() {
- textAreaFocus(textArea, false);
- textArea.setText(textArea.getName());
- for (int i = 0; i < MAXTEXTFIELDS - 1; i++){
- textField[i].setText(textField[i].getName());
- textFieldFocus(textField[i], false);
- }
- }
- public void turnConfirmButton(boolean turn) {
- if (turn) {
- confirmLabel.setVisible(true);
- button[1].setText("Confirmar");
- button[2].setText("Voltar");
- }
- else {
- confirmLabel.setVisible(false);
- button[1].setText(buttonText[1]);
- button[2].setText(buttonText[2]);
- }
- }
- private JLabel confirmLabel;
- private JPanel mainPanel, topPanel, contentPanel, actionPanel;
- public int MAXBUTTONS = 3, MAXTEXTFIELDS = 5;
- private int buttonY[] = {150, 20, 260};
- private int buttonX[] = {20, 5, 5};
- private JButton button[] = new JButton[MAXBUTTONS];
- private String buttonText[] = {"Inserir", "Atualizar", "Deletar"};
- private int textFieldX[] = {10, 60, 110, 160, 210}; //ultimo pertence ao textArea
- private JTextField textField[] = new JTextField[MAXTEXTFIELDS-1]; // 1 pertence ao TextArea
- private String textFieldText[] = {"Pokemon ID", "Nome do Pokemon", "Fraqueza", "Vantagem", "Descrição"};
- private JTextArea textArea;
- private JComboBox comboBox;
- public boolean state = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement