/** Install Add and Remove Buttons into the toolbar */ private void installAddRemovePointButtons() { URL imgURL = ClassLoader.getSystemResource("ch/tbe/pics/plus.gif"); ImageIcon plus = new ImageIcon(imgURL); imgURL = ClassLoader.getSystemResource("ch/tbe/pics/minus.gif"); ImageIcon minus = new ImageIcon(imgURL); add = new JButton(plus); rem = new JButton(minus); add.setToolTipText(workingViewLabels.getString("plus")); rem.setToolTipText(workingViewLabels.getString("minus")); add.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { WorkingView.this.addRemovePoint(true); } }); rem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { WorkingView.this.addRemovePoint(false); } }); add.setContentAreaFilled(false); add.setBorderPainted(false); rem.setContentAreaFilled(false); rem.setBorderPainted(false); toolbar.add(add); toolbar.add(rem); }
private void initMainPanel() { mainPanel = new JPanel(null); searchField = new JTextField(); searchField.setBounds(50, 50, 830, 20); searchField .getDocument() .addDocumentListener( new DocumentListener() { @Override public void insertUpdate(DocumentEvent e) {} @Override public void removeUpdate(DocumentEvent e) { listSearchTable = null; } @Override public void changedUpdate(DocumentEvent e) {} }); searchField.addActionListener(new Action()); searchButton = new JButton( new ImageIcon( "/home/mrhappyyy/Programing/Java/Project/Laboratory/Client_Laboratory/src/windows/search.png")); searchButton.setBorderPainted(false); searchButton.setBounds(900, 35, 50, 50); searchButton.addActionListener(new Action()); updateTable = new JButton( new ImageIcon( "/home/mrhappyyy/Programing/Java/Project/Laboratory/Client_Laboratory/src/windows/refresh.png")); updateTable.setBorderPainted(false); updateTable.setBounds(900, 100, 50, 50); updateTable.addActionListener(new Action()); productTableModel = new ProductTableModel(); table = new JTable(productTableModel); scroll = new JScrollPane(table); scroll.setBounds(50, 85, 830, 450); mainPanel.add(searchField); mainPanel.add(searchButton); mainPanel.add(updateTable); mainPanel.add(scroll); clarificationPanel.add(mainPanel, "mainPanel"); updateTable(); layout.show(clarificationPanel, "mainPanel"); }
public JButton ButtonProperties(JButton button) { button.setFont(componentFont); button.setBorderPainted(false); button.setFocusPainted(false); button.setBackground(themeColor1); button.setForeground(themeColor4); button.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { button.setBackground(themeColor2); button.setForeground(Color.BLACK); } @Override public void mouseExited(MouseEvent e) { button.setBackground(themeColor1); button.setForeground(themeColor4); } }); return button; }
public JButton ButtonProperties(JButton button, String buttonText) { button.setFont(componentFont); button.setBorderPainted(false); button.setFocusPainted(false); button.setBackground(themeColor1); button.setForeground(themeColor4); button.setVerticalTextPosition(SwingConstants.BOTTOM); button.setHorizontalTextPosition(SwingConstants.CENTER); button.addMouseListener( new MouseAdapter() { @Override public void mouseEntered(MouseEvent e) { button.setBackground(themeColor2); button.setForeground(Color.BLACK); button.setText(buttonText); } @Override public void mouseExited(MouseEvent e) { button.setBackground(themeColor1); button.setForeground(themeColor4); button.setText(""); } }); return button; }
/** * Installs a Tool in the Toolbar * * @param toolbar as JToolbar * @param tool, Tool to install */ public void installToolInToolBar(JToolBar toolbar, final Tool tool) { final JButton button; button = new JButton(); button.setMargin(new Insets(0, 0, 0, 0)); if (tool.getItemType() != null) { button.setIcon(tool.getItemType().getIcon()); button.setToolTipText(tool.getItemType().getDescription()); } else { button.setText("Tool"); // For Debugging } toolbar.add(button); toolButtons.add(button); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { WorkingView.this.setTool(tool, button); } }); button.setContentAreaFilled(false); button.setBorderPainted(false); button.addMouseListener( new MouseAdapter() { public void mouseEntered(MouseEvent e) { ((JButton) e.getSource()).setBorderPainted(true); } public void mouseExited(MouseEvent e) { ((JButton) e.getSource()).setBorderPainted(false); } }); }
@Override public JComponent createUI( DescriptionType inputOrOutput, Map<URI, Object> dataMap, Orientation orientation) { // Create the main panel JComponent component = new JPanel(new MigLayout("fill")); boolean isOptional = false; if (inputOrOutput instanceof InputDescriptionType) { isOptional = ((InputDescriptionType) inputOrOutput).getMinOccurs().equals(new BigInteger("0")); } // Display the SourceCA into a JTextField JTextField jtf = new JTextField(); jtf.setToolTipText(inputOrOutput.getAbstract().get(0).getValue()); // "Save" the CA inside the JTextField jtf.getDocument().putProperty(DATA_MAP_PROPERTY, dataMap); URI uri = URI.create(inputOrOutput.getIdentifier().getValue()); jtf.getDocument().putProperty(URI_PROPERTY, uri); // add the listener for the text changes in the JTextField jtf.getDocument() .addDocumentListener( EventHandler.create(DocumentListener.class, this, "saveDocumentText", "document")); if (isOptional) { if (dataMap.containsKey(uri)) { jtf.setText(dataMap.get(uri).toString()); } } GeometryData geometryData = null; if (inputOrOutput instanceof InputDescriptionType) { geometryData = (GeometryData) ((InputDescriptionType) inputOrOutput).getDataDescription().getValue(); } // If the DescriptionType is an output, there is nothing to show, so exit if (geometryData == null) { return null; } component.add(jtf, "growx"); if (orientation.equals(Orientation.VERTICAL)) { JPanel buttonPanel = new JPanel(new MigLayout()); // Create the button Browse JButton pasteButton = new JButton(ToolBoxIcon.getIcon(ToolBoxIcon.PASTE)); // "Save" the sourceCA and the JTextField in the button pasteButton.putClientProperty(TEXT_FIELD_PROPERTY, jtf); pasteButton.setBorderPainted(false); pasteButton.setContentAreaFilled(false); pasteButton.setMargin(new Insets(0, 0, 0, 0)); // Add the listener for the click on the button pasteButton.addActionListener(EventHandler.create(ActionListener.class, this, "onPaste", "")); buttonPanel.add(pasteButton); component.add(buttonPanel, "dock east"); } return component; }
private void initButton(JButton button) { button.setText(""); button.setBorder(RAISED_BORDER); button.setBorderPainted(false); button.setFocusPainted(false); button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); }
private void setupToolBar() { // setup the buttons buttonRecord.setIcon(imageiconRecord); buttonRecord.setDisabledIcon(imageiconRecordDisabled); buttonRecord.setPressedIcon(imageiconRecordDisabled); buttonRecord.setBorderPainted(false); buttonPause.setIcon(imageiconPause); buttonPause.setDisabledIcon(imageiconPauseDisabled); buttonPause.setPressedIcon(imageiconPauseDisabled); buttonPause.setBorderPainted(false); buttonRecord.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (model.isRecord()) { model.setRecord(false); } else { model.setRecord(true); } } }); buttonPause.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (model.isPause()) { model.setPause(false); } else { model.setPause(true); } } }); buttonRecord.setEnabled(!model.isRecord()); buttonPause.setEnabled(!model.isPause()); // add the view to the toolbar setLayout(new GridLayout(1, 1)); add(panelMain); }
/** * _more_ * * @param type * @return _more_ */ private JButton createButton(SpinIcon.Type type) { SpinIcon icon = new SpinIcon(type); JButton butt = new JButton(icon); Insets i = new Insets(0, 0, 0, 0); butt.setMargin(i); butt.setBorderPainted(false); butt.setFocusPainted(false); butt.setPreferredSize(new Dimension(icon.getIconWidth() + 2, icon.getIconHeight() + 2)); return butt; }
public Abschluss(String wahl, Sudoku s, Sudoku2 s2) { super("Sudoku-Abschluss"); this.setSize(270, 135); this.setLocation(250, 300); this.setLayout(null); this.setAlwaysOnTop(true); this.setResizable(false); this.setUndecorated(true); if (s == null) this.setLocationRelativeTo(s2); else this.setLocationRelativeTo(s); su = s; su2 = s2; w = wahl; ImageIcon icon = new ImageIcon("files/minigames/Sudoku/beispiel2.jpg"); icon.setImage(icon.getImage().getScaledInstance(290, 135, Image.SCALE_DEFAULT)); lab = new JLabel(icon); lab.setSize(270, 135); lab.setLocation(0, 0); this.add(lab); text = new JLabel(); text.setSize(250, 20); text.setLocation(10, 10); text.setForeground(Color.white); text.setHorizontalAlignment(0); lab.add(text); text2 = new JLabel(); text2.setSize(270, 20); text2.setLocation(10, 30); text2.setForeground(Color.white); lab.add(text2); ok = new JButton("OK"); ok.setSize(90, 30); ok.setLocation(80, 50); ok.setBorderPainted(false); ok.setBackground(Color.lightGray); ok.setForeground(Color.lightGray); ok.setOpaque(false); ok.setFont(new Font("Arial Black", 4, 20)); ok.setContentAreaFilled(false); ok.setFocusPainted(false); ok.addActionListener(this); ok.addMouseListener(this); lab.add(ok); textWahl(wahl); this.setVisible(true); }
{ rendererEditor = new JButton(MainIconManager.getIcon("error_go")); rendererEditor.setBorderPainted(false); rendererEditor.setContentAreaFilled(false); rendererEditor.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialog.setText(detailsHandlers.getHandler(value).getMessage(value)); dialog.setVisible(true); } }); }
/** * Constructor. * * @param title the title of the tab component * @param editor the editor of the tab (used to close the tab) */ public TabComponent(final AbstractEditorPanel editor) { setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(3, 0, 0, 0)); setOpaque(false); // title title = new JLabel(editor.getTitle()); title.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); add(title, BorderLayout.WEST); // close final JButton close = new JButton(Project.getEditorImageIconOrEmpty("icon_cross.png")); close.setPreferredSize(new Dimension(16, 16)); close.setUI(new BasicButtonUI()); close.setBorderPainted(false); close.setOpaque(false); close.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { removeEditor(editor, true); } }); close.addMouseListener( new MouseListener() { @Override public void mouseClicked(MouseEvent me) {} @Override public void mousePressed(MouseEvent me) {} @Override public void mouseReleased(MouseEvent me) {} @Override public void mouseEntered(MouseEvent me) { close.setBorderPainted(true); } @Override public void mouseExited(MouseEvent me) { close.setBorderPainted(false); } }); add(close, BorderLayout.EAST); }
public BorderedComponent(String text, JComponent comp, boolean collapsible) { super(null); this.comp = comp; // Only add border if text is not null if (text != null) { TitledBorder border; if (collapsible) { final JLabel textLabel = new JLabel(text); JPanel borderLabel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 0)) { public int getBaseline(int w, int h) { Dimension dim = textLabel.getPreferredSize(); return textLabel.getBaseline(dim.width, dim.height) + textLabel.getY(); } }; borderLabel.add(textLabel); border = new LabeledBorder(borderLabel); textLabel.setForeground(border.getTitleColor()); if (IS_WIN) { collapseIcon = new ImageIcon(getImage("collapse-winlf")); expandIcon = new ImageIcon(getImage("expand-winlf")); } else { collapseIcon = new ArrowIcon(SOUTH, textLabel); expandIcon = new ArrowIcon(EAST, textLabel); } moreOrLessButton = new JButton(collapseIcon); moreOrLessButton.setContentAreaFilled(false); moreOrLessButton.setBorderPainted(false); moreOrLessButton.setMargin(new Insets(0, 0, 0, 0)); moreOrLessButton.addActionListener(this); String toolTip = Messages.BORDERED_COMPONENT_MORE_OR_LESS_BUTTON_TOOLTIP; moreOrLessButton.setToolTipText(toolTip); borderLabel.add(moreOrLessButton); borderLabel.setSize(borderLabel.getPreferredSize()); add(borderLabel); } else { border = new TitledBorder(text); } setBorder(new CompoundBorder(new FocusBorder(this), border)); } else { setBorder(new FocusBorder(this)); } if (comp != null) { add(comp); } }
public Buttons() { setPreferredSize(new Dimension(w, h)); setBackground(new Color(0, 0, 0, 0)); setLayout(new BorderLayout()); min = new JButton("-"); plus = new JButton("+"); // min.setPreferredSize(new Dimension(100,10)); // plus.setPreferredSize(new Dimension(100,10)); min.setBackground(Color.WHITE); plus.setBackground(Color.WHITE); min.setOpaque(false); plus.setOpaque(false); min.setBorderPainted(true); min.setFocusPainted(true); plus.setFocusPainted(true); plus.setBorderPainted(true); min.addActionListener(this); plus.addActionListener(this); min.setActionCommand("-"); plus.setActionCommand("+"); add(plus, BorderLayout.NORTH); add(min, BorderLayout.CENTER); }
public Login() { back = Toolkit.getDefaultToolkit().getImage("img/monkey_back3.jpg"); // LOGIN창 배경이미지 lab1 = new JLabel("ID"); // 선언부 lab2 = new JLabel("PW"); tf = new JTextField(); pf = new JPasswordField(); bt1 = new JButton(joinButton); bt2 = new JButton(loginButton); setLayout(null); // 사용자 직접 배치!! JPanel p = new JPanel(); p.setBounds(200, 250, 220, 150); // p의 위치조정 p.setLayout(null); lab1.setBounds(10, 15, 30, 30); // 0,0기준으로 10,15는 간격, 30,30은 lab1의 가로세로크기 tf.setBounds(45, 15, 150, 30); // 0,0기준으로 10+30=40,15는 간격 lab2.setBounds(10, 50, 30, 30); // 높이:15+30+5(간격)=50 pf.setBounds(45, 50, 150, 30); bt1.setBounds(15, 95, 90, 40); bt2.setBounds(120, 95, 90, 40); bt1.setBorderPainted(false); bt1.setContentAreaFilled(false); bt2.setBorderPainted(false); bt2.setContentAreaFilled(false); p.setOpaque(false); // JPanel묶은것 회색을 투명하게! p.add(lab1); p.add(tf); p.add(lab2); p.add(pf); p.add(bt1); p.add(bt2); add(p); // JPanel로 묶음을 화면에 추가 }
/** * The class constructor. * * <p>Adds and creates a message saying bye. */ public Instruction2() { setLayout(null); JButton back = new JButton(new ImageIcon("Back.png")); back.setOpaque(false); back.setContentAreaFilled(false); back.setBorderPainted(false); back.setFocusable(false); back.setRolloverIcon(new ImageIcon("Backrollover.png")); back.setActionCommand("Back"); back.addActionListener(this); JLabel pic = new JLabel(new ImageIcon("Instructions2.png")); pic.setBounds(0, 0, pic.getPreferredSize().width, pic.getPreferredSize().height); back.setBounds(5, 200, back.getPreferredSize().width, back.getPreferredSize().height); add(pic); add(back); }
public ProgressPanel(final NodeBoxDocument document) { setMinimumSize(new Dimension(0, PROGRESS_PANEL_HEIGHT)); setMaximumSize(new Dimension(PROGRESS_PANEL_WIDTH, PROGRESS_PANEL_HEIGHT)); setPreferredSize(new Dimension(PROGRESS_PANEL_WIDTH, PROGRESS_PANEL_HEIGHT)); setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0)); stopButton = new JButton(stopOffIcon); stopButton.setBorderPainted(false); stopButton.setBorder(null); stopButton.setSize(19, 19); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { document.stopRendering(); } }); add(stopButton); }
/** * Creates the view class * * @param controller The controller of the view class */ public SelectMazeView(SelectMazeController controller) { this.controller = controller; this.mazelist = this.controller.getMazelist(); this.setPreferredSize(new Dimension(500, 500)); this.setLayout(new BorderLayout()); this.setBackground(Color.WHITE); this.setOpaque(true); this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); this.selectMazeLabel = new JLabel("Select a maze"); this.selectMazeLabel.setFont(new Font("Sans Serif", Font.PLAIN, 20)); this.selectMazeLabel.setForeground(Color.BLACK); this.selectMazeLabel.setOpaque(false); this.selectMazeLabel.setPreferredSize(new Dimension(500, 70)); this.selectMazeLabel.setHorizontalAlignment(JLabel.CENTER); this.listpanel = new JPanel(); this.listpanel.setOpaque(false); this.listpanel.setLayout(new FlowLayout()); this.add(this.selectMazeLabel, BorderLayout.NORTH); this.add(this.listpanel, BorderLayout.CENTER); int i = 0; while (i < this.mazelist.size()) { String mazename = this.mazelist.get(i); JButton mazeButton = new JButton(mazename); mazeButton.addMouseListener(this.mazeButtonListener); mazeButton.setFont(new Font("Sans Serif", Font.PLAIN, 16)); mazeButton.setForeground(Color.DARK_GRAY); mazeButton.setOpaque(false); mazeButton.setContentAreaFilled(false); mazeButton.setBorderPainted(false); mazeButton.setOpaque(true); this.listpanel.add(mazeButton); i++; } }
public void setUseFlatUI(boolean b) { main.setContentAreaFilled(!b); main.setFocusPainted(!b); main.setBorderPainted(!b); main.setMargin(new Insets(1, 1, 1, 1)); popper.setContentAreaFilled(!b); popper.setFocusPainted(!b); popper.setBorderPainted(!b); popper.setMargin(new Insets(1, 1, 1, 1)); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setOpaque(false); MouseAdapter ma = new MouseAdapter() { public void mouseEntered(MouseEvent e) { main.setContentAreaFilled(true); main.setBackground(new Color(216, 240, 254)); // m.getMainButton().setForeground( Color.black ); setBorder(new LineBorder(new Color(200, 200, 200), 1)); setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); popper.setBackground(new Color(242, 242, 242)); popper.setContentAreaFilled(true); popper.setBorder(menu.getBorder()); } public void mouseExited(MouseEvent e) { main.setContentAreaFilled(false); // c.setForeground( Color.black ); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setCursor(Cursor.getDefaultCursor()); popper.setContentAreaFilled(false); popper.setBorder(null); } }; main.addMouseListener(ma); popper.addMouseListener(ma); }
Spacer(ZoneModel model, int index, SpacerHandle knobHandle) { this.model = model; this.index = index; this.knobHandle = knobHandle; knobPainter = new KnobPainter(this); setOpaque(false); setCursor(SliderCursor); initKeyMaps(); Icon icon = getIcon("unstick"); Icon pressedIcon = getIcon("unstickPressed"); Icon highlightIcon = getIcon("unstickHighlight"); unstickButton = new JButton(icon); unstickButton.setSize(icon.getIconWidth(), icon.getIconHeight()); unstickButton.setPressedIcon(pressedIcon); unstickButton.setRolloverEnabled(true); unstickButton.setRolloverIcon(highlightIcon); unstickButton.setBorder(null); unstickButton.putClientProperty(SubstanceLookAndFeel.BUTTON_PAINT_NEVER_PROPERTY, Boolean.TRUE); unstickButton.setBorderPainted(false); unstickButton.setRolloverEnabled(true); unstickButton.setOpaque(false); unstickButton.setCursor(ClickCursor); unstickButton.setFocusable(false); unstickButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { Spacer.this.model.removePoint(Spacer.this.index); } }); if (model.containsPoint(index)) { add(unstickButton); } model.addZoneModelListener(this); setFocusable(true); addFocusListener(this); addMouseListener(this); }
public IUmenu(String host) { setTitle("GUUERRA_NAVAL"); efectos = new Efectos(); try { cliente = new Cliente(host); } catch (Exception ex) { } /* Titulo */ titulo = new JLabel(" JHONMAN "); titulo.setForeground(Color.BLACK); titulo.setFont(new Font("Algerian", Font.BOLD, 24)); titulo.setBounds(120, 40, 560, 40); titulo.setHorizontalAlignment(JLabel.CENTER); /* MeEnu de Opciones */ mEnU = new JLabel("MENU DE OPCIONES"); mEnU.setForeground(Color.BLACK); mEnU.setFont(new Font("Algerian", Font.BOLD, 24)); mEnU.setBounds(40, 135, 390, 40); mEnU.setHorizontalAlignment(JLabel.LEFT); ImageIcon i = new ImageIcon("imagenes/apariencia/fondo_def.jpg"); fondo = new JLabel(new ImageIcon(i.getImage().getScaledInstance(800, 600, Image.SCALE_SMOOTH))); fondo.setBounds(0, 0, 800, 600); ImageIcon i1 = new ImageIcon("imagenes/apariencia/botRegistrar.jpg"); ImageIcon i2 = new ImageIcon("imagenes/apariencia/botPrincipiante.jpg"); ImageIcon i3 = new ImageIcon("imagenes/apariencia/botDificil.jpg"); ImageIcon i4 = new ImageIcon("imagenes/apariencia/botSalir.jpg"); ImageIcon i5 = new ImageIcon("imagenes/apariencia/botRaking.jpg"); ImageIcon i6 = new ImageIcon("imagenes/apariencia/brJuegoRed2.jpg"); ImageIcon i11 = new ImageIcon("imagenes/apariencia/botRegistrar2.jpg"); ImageIcon i22 = new ImageIcon("imagenes/apariencia/botPrincipiante2.jpg"); ImageIcon i33 = new ImageIcon("imagenes/apariencia/botDificil2.jpg"); ImageIcon i44 = new ImageIcon("imagenes/apariencia/botSalir2.jpg"); ImageIcon i55 = new ImageIcon("imagenes/apariencia/botRaking2.jpg"); ImageIcon i66 = new ImageIcon("imagenes/apariencia/brJuegoRed.jpg"); /* Boton Puntajes */ estad = new JButton(new ImageIcon(i5.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); estad.setBounds(98, 148, 170, 40); estad.setRolloverIcon( new ImageIcon( i55.getImage() .getScaledInstance( 170, 40, Image .SCALE_SMOOTH))); // cuando el mouse esta sobre el boton cambia a esta // imagen estad.setBorderPainted(false); // elimino los bordes de el boton estad.addActionListener(this); estad.setMnemonic(KeyEvent.VK_P); estad.setToolTipText("ver Raking ALT + P"); /* Boton Registrar */ registrar = new JButton(new ImageIcon(i1.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); registrar.setBounds(98, 205, 170, 40); registrar.setRolloverIcon( new ImageIcon(i11.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); registrar.setBorderPainted(false); registrar.addActionListener(this); registrar.setMnemonic(KeyEvent.VK_Q); registrar.setToolTipText("Registrarse ALT + Q"); /* Boton TipoFacil */ facil = new JButton(new ImageIcon(i2.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); facil.setBounds(97, 262, 170, 40); facil.setRolloverIcon( new ImageIcon(i22.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); facil.setBorderPainted(false); facil.addActionListener(this); facil.setMnemonic(KeyEvent.VK_F); facil.setToolTipText("jugar en modo principiante ALT + F"); /* Boton TipoDificil */ dific = new JButton(new ImageIcon(i3.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); dific.setBounds(97, 317, 170, 40); dific.setRolloverIcon( new ImageIcon(i33.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); dific.setBorderPainted(false); dific.addActionListener(this); dific.setMnemonic(KeyEvent.VK_D); dific.setToolTipText("jugar en modo dificil ALT + D"); /* Boton Salir */ salir = new JButton(new ImageIcon(i4.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); salir.setBounds(97, 430, 170, 40); salir.setRolloverIcon( new ImageIcon(i44.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); salir.setBorderPainted(false); salir.addActionListener(this); salir.setMnemonic(KeyEvent.VK_S); salir.setToolTipText("Salir ALT + S"); /* Boton Red */ red = new JButton(new ImageIcon(i6.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); red.setBounds(97, 374, 170, 40); red.setRolloverIcon( new ImageIcon(i66.getImage().getScaledInstance(170, 40, Image.SCALE_SMOOTH))); red.setBorderPainted(false); red.addActionListener(this); red.setMnemonic(KeyEvent.VK_C); red.setToolTipText("Jugar con varios jugadores ALT + C"); c = getContentPane(); c.setLayout(null); c.add(titulo); c.add(estad); c.add(facil); c.add(registrar); c.add(dific); c.add(salir); c.add(red); c.add(fondo); }
public void initialize(final Controller controller) { super.initialize(controller); WWMenu fileMenu = (WWMenu) this.getController().getRegisteredObject(Constants.FILE_MENU); if (fileMenu != null) fileMenu.addMenu(this.getFeatureID()); this.tabbedPane = new JTabbedPane(); this.tabbedPane.setOpaque(false); this.tabbedPane.add(new JPanel()); this.tabbedPane.setTitleAt(0, "+"); // this tab is just a button for adding servers/panels this.tabbedPane.setToolTipTextAt(0, "Connect to WMS Server"); this.tabbedPane.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent changeEvent) { if (tabbedPane.getSelectedIndex() == 0) { addNewPanel(tabbedPane); // Add new panel when '+' is selected } } }); // Add an initial panel to the tabbed pane this.addNewPanel(this.tabbedPane); tabbedPane.setSelectedIndex(1); this.setTaskComponent(this.tabbedPane); this.setLocation(SwingConstants.CENTER, SwingConstants.CENTER); this.getJDialog().setResizable(true); JButton deleteButton = new JButton(ImageLibrary.getIcon("gov/nasa/worldwindow/images/delete-20x20.png")); deleteButton.setToolTipText("Remove Server"); deleteButton.setOpaque(false); deleteButton.setBackground(new Color(0, 0, 0, 0)); deleteButton.setBorderPainted(false); deleteButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { deleteCurrentPanel(); } }); deleteButton.setEnabled(true); this.insertLeftDialogComponent(deleteButton); // // JButton cancelButton = new JButton("Cancel"); // cancelButton.setToolTipText("Cancel capabilities retrieval from server"); // cancelButton.setOpaque(false); // cancelButton.addActionListener(new ActionListener() // { // public void actionPerformed(ActionEvent actionEvent) // { // cancelCurrentRetrieval(); // } // }); // this.insertRightDialogComponent(cancelButton); this.setTitle("WMS Servers"); this.dialog.validate(); this.dialog.pack(); }
private void setLookLowered(JButton button) { button.setBorder(LOWERED_BORDER); button.setHorizontalAlignment(SwingConstants.RIGHT); button.setVerticalAlignment(SwingConstants.BOTTOM); button.setBorderPainted(true); }
private void setLookRaised(JButton button) { button.setBorder(RAISED_BORDER); button.setHorizontalAlignment(SwingConstants.CENTER); button.setVerticalAlignment(SwingConstants.CENTER); button.setBorderPainted(true); }
public IllegalMovePopUp() { setTitle("THIS IS ILLEGAL"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); setBackground(Color.WHITE); JPanel center = new JPanel(); center.setBackground(color); center.setLayout(new GridBagLayout()); JLabel cross = new JLabel(image); cross.setBackground(color); center.add(cross); cross.setBorder(new EmptyBorder(10, 10, 0, 10)); cross.setHorizontalAlignment(JLabel.CENTER); cross.setVerticalAlignment(JLabel.CENTER); JPanel doubleColumn = new JPanel(); doubleColumn.setBackground(color); doubleColumn.setLayout(new GridLayout(2, 1)); center.add(doubleColumn); JLabel invalid = new JLabel("invalid move "); invalid.setBackground(color); invalid.setForeground(Color.WHITE); invalid.setFont(new Font("Georgia", Font.BOLD, 30)); doubleColumn.add(invalid); invalid.setHorizontalAlignment(JLabel.CENTER); invalid.setVerticalAlignment(JLabel.CENTER); JLabel tryAgain = new JLabel("Try Again!"); tryAgain.setBackground(color); tryAgain.setForeground(Color.WHITE); tryAgain.setFont(new Font("Courier New", Font.PLAIN, 20)); doubleColumn.add(tryAgain); tryAgain.setHorizontalAlignment(JLabel.CENTER); tryAgain.setVerticalAlignment(JLabel.CENTER); JPanel south = new JPanel(); south.setBackground(color); JPanel forTheButton = new JPanel(); forTheButton.setBackground(color); JButton OK = new JButton("OK"); OK.setBorderPainted(false); OK.setFocusPainted(false); OK.setBackground(Color.BLACK); OK.setForeground(Color.WHITE); OK.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { dispose(); } }); forTheButton.add(OK); south.add(forTheButton); add(center, BorderLayout.CENTER); add(south, BorderLayout.SOUTH); pack(); setSize(450, 200); setVisible(true); setAlwaysOnTop(true); setLocationRelativeTo(null); }
/** * Creates and return an instance of JButton that can be used to collapse the right component in * the metal split pane. */ protected JButton createRightOneTouchButton() { JButton b = new JButton() { // Sprite buffer for the arrow image of the right button int[][] buffer = { {2, 2, 2, 2, 2, 2, 2, 2}, {0, 1, 1, 1, 1, 1, 1, 3}, {0, 0, 1, 1, 1, 1, 3, 0}, {0, 0, 0, 1, 1, 3, 0, 0}, {0, 0, 0, 0, 3, 0, 0, 0} }; public void setBorder(Border border) {} public void paint(Graphics g) { JSplitPane splitPane = getSplitPaneFromSuper(); if (splitPane != null) { int oneTouchSize = getOneTouchSizeFromSuper(); int orientation = getOrientationFromSuper(); int blockSize = Math.min(getDividerSize(), oneTouchSize); // Initialize the color array Color[] colors = { this.getBackground(), MetalLookAndFeel.getPrimaryControlDarkShadow(), MetalLookAndFeel.getPrimaryControlInfo(), MetalLookAndFeel.getPrimaryControlHighlight() }; // Fill the background first ... g.setColor(this.getBackground()); if (isOpaque()) { g.fillRect(0, 0, this.getWidth(), this.getHeight()); } // ... then draw the arrow. if (getModel().isPressed()) { // Adjust color mapping for pressed button state colors[1] = colors[2]; } if (orientation == JSplitPane.VERTICAL_SPLIT) { // Draw the image for a vertical split for (int i = 1; i <= buffer[0].length; i++) { for (int j = 1; j < blockSize; j++) { if (buffer[j - 1][i - 1] == 0) { continue; } else { g.setColor(colors[buffer[j - 1][i - 1]]); } g.drawLine(i, j, i, j); } } } else { // Draw the image for a horizontal split // by simply swaping the i and j axis. // Except the drawLine() call this code is // identical to the code block above. This was done // in order to remove the additional orientation // check for each pixel. for (int i = 1; i <= buffer[0].length; i++) { for (int j = 1; j < blockSize; j++) { if (buffer[j - 1][i - 1] == 0) { // Nothing needs // to be drawn continue; } else { // Set the color from the // color map g.setColor(colors[buffer[j - 1][i - 1]]); } // Draw a pixel g.drawLine(j, i, j, i); } } } } } // Don't want the button to participate in focus traversable. public boolean isFocusTraversable() { return false; } }; b.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); b.setFocusPainted(false); b.setBorderPainted(false); b.setRequestFocusEnabled(false); maybeMakeButtonOpaque(b); return b; }
/* * main constructor * @param debug - boolean for debug mode */ public boardPanel(boolean debug) { // initial constructor super(); debugBoardPanel = debug; // continue defining boardPanel this.setLayout(new GridBagLayout()); cons.fill = GridBagConstraints.BOTH; cons.insets = new Insets(0, 0, 0, 0); cons.anchor = GridBagConstraints.FIRST_LINE_START; this.setVisible(true); // button preferred size Dimension btnSize = new Dimension(25, 25); // top row // ------------------------------------------------------------------------------------------ // spa btnSpa = new JButton("Spa"); allRooms[0] = btnSpa; btnSpa.setPreferredSize(btnSize); cons.gridx = 0; cons.gridy = 0; cons.gridwidth = 5; cons.gridheight = 5; btnSpa.setBackground(defaultRoomColor); btnSpa.setOpaque(true); btnSpa.setBorderPainted(false); btnSpa.addActionListener(new myActionListener()); this.add(btnSpa, cons); // space buttons for (int y = 0; y < 5; y++) { for (int x = 5; x < 10; x++) { createBlankButtons(x, y, btnSize); } } // theater btnTheater = new JButton("Theater"); allRooms[1] = btnTheater; btnTheater.setPreferredSize(btnSize); cons.gridx = 10; cons.gridy = 0; cons.gridwidth = 5; cons.gridheight = 5; btnTheater.setOpaque(true); btnTheater.setBorderPainted(false); btnTheater.setBackground(defaultRoomColor); btnTheater.addActionListener(new myActionListener()); this.add(btnTheater, cons); // space buttons for (int y = 0; y < 5; y++) { for (int x = 15; x < 20; x++) { createBlankButtons(x, y, btnSize); } } // Living Room btnLivingRoom = new JButton("Living Room"); allRooms[2] = btnLivingRoom; btnLivingRoom.setPreferredSize(btnSize); cons.gridx = 20; cons.gridy = 0; cons.gridwidth = 5; cons.gridheight = 5; btnLivingRoom.setBackground(defaultRoomColor); btnLivingRoom.setOpaque(true); btnLivingRoom.setBorderPainted(false); btnLivingRoom.addActionListener(new myActionListener()); this.add(btnLivingRoom, cons); // space buttons for (int y = 0; y < 5; y++) { for (int x = 25; x < 30; x++) { createBlankButtons(x, y, btnSize); } } // observatory btnObservatory = new JButton("Observatory"); allRooms[3] = btnObservatory; btnObservatory.setPreferredSize(btnSize); cons.gridx = 30; cons.gridy = 0; cons.gridwidth = 5; cons.gridheight = 5; btnObservatory.setBackground(defaultRoomColor); btnObservatory.setOpaque(true); btnObservatory.setBorderPainted(false); btnObservatory.addActionListener(new myActionListener()); this.add(btnObservatory, cons); // top to middle spaces // ------------------------------------------------------------------------------------------ // space buttons for (int y = 5; y < 10; y++) { for (int x = 0; x < 35; x++) { createBlankButtons(x, y, btnSize); } } // middle row // ------------------------------------------------------------------------------------------ // Patio btnPatio = new JButton("Patio"); allRooms[4] = btnPatio; btnPatio.setPreferredSize(btnSize); cons.gridx = 0; cons.gridy = 10; cons.gridwidth = 5; cons.gridheight = 5; btnPatio.setBackground(defaultRoomColor); btnPatio.setOpaque(true); btnPatio.setBorderPainted(false); btnPatio.addActionListener(new myActionListener()); this.add(btnPatio, cons); // space buttons for (int y = 10; y < 15; y++) { for (int x = 5; x < 10; x++) { createBlankButtons(x, y, btnSize); } } // pool btnPool = new JButton("Pool"); allRooms[5] = btnPool; btnPool.setPreferredSize(btnSize); cons.gridx = 10; cons.gridy = 10; cons.gridwidth = 15; cons.gridheight = 5; btnPool.setBackground(defaultPoolColor); btnPool.setOpaque(true); btnPool.setBorderPainted(false); btnPool.addActionListener(new myActionListener()); this.add(btnPool, cons); // space buttons for (int y = 10; y < 15; y++) { for (int x = 25; x < 30; x++) { createBlankButtons(x, y, btnSize); } } // Hall btnHall = new JButton("Hall"); allRooms[6] = btnHall; btnHall.setPreferredSize(btnSize); cons.gridx = 30; cons.gridy = 10; cons.gridwidth = 5; cons.gridheight = 5; btnHall.setBackground(defaultRoomColor); btnHall.setOpaque(true); btnHall.setBorderPainted(false); btnHall.addActionListener(new myActionListener()); this.add(btnHall, cons); // middle to bottom spaces // ------------------------------------------------------------------------------------------ // space buttons for (int y = 15; y < 20; y++) { for (int x = 0; x < 35; x++) { createBlankButtons(x, y, btnSize); } } // bottom row // ------------------------------------------------------------------------------------------ // Kitchen btnKitchen = new JButton("Kitchen"); allRooms[7] = btnKitchen; btnKitchen.setPreferredSize(btnSize); cons.gridx = 0; cons.gridy = 20; cons.gridwidth = 5; cons.gridheight = 5; btnKitchen.setBackground(defaultRoomColor); btnKitchen.setOpaque(true); btnKitchen.setBorderPainted(false); btnKitchen.addActionListener(new myActionListener()); this.add(btnKitchen, cons); // space buttons for (int y = 20; y < 25; y++) { for (int x = 5; x < 10; x++) { createBlankButtons(x, y, btnSize); } } // dining room btnDiningRoom = new JButton("Dining Room"); allRooms[8] = btnDiningRoom; btnPool.setPreferredSize(btnSize); cons.gridx = 10; cons.gridy = 20; cons.gridwidth = 15; cons.gridheight = 5; btnDiningRoom.setBackground(defaultRoomColor); btnDiningRoom.setOpaque(true); btnDiningRoom.setBorderPainted(false); btnDiningRoom.addActionListener(new myActionListener()); this.add(btnDiningRoom, cons); // space buttons for (int y = 20; y < 25; y++) { for (int x = 25; x < 30; x++) { createBlankButtons(x, y, btnSize); } } // Guest House btnGuestHouse = new JButton("Guest House"); allRooms[9] = btnGuestHouse; btnGuestHouse.setPreferredSize(btnSize); cons.gridx = 30; cons.gridy = 20; cons.gridwidth = 5; cons.gridheight = 5; btnGuestHouse.setBackground(defaultRoomColor); btnGuestHouse.setOpaque(true); btnGuestHouse.setBorderPainted(false); btnGuestHouse.addActionListener(new myActionListener()); this.add(btnGuestHouse, cons); // textArea // ------------------------------------------------------------------------------------------ // create textarea for output cons.gridx = 0; cons.gridy = 25; cons.gridwidth = 35; this.add(jsp, cons); }
public static void main(String... args) { JFrame frame = new JFrame(); frame.setTitle("Game Of Life"); JMenuBar toolBar = new JMenuBar(); JButton start = new JButton(getImageIcon("/icons/play_icon.png")); start.setToolTipText("Run"); start.setBorderPainted(false); JButton reset = new JButton(getImageIcon("/icons/reset_icon.png")); reset.setToolTipText("Clear field"); reset.setBorderPainted(false); JButton next = new JButton(getImageIcon("/icons/next_icon.png")); next.setToolTipText("Next step"); next.setBorderPainted(false); JButton pause = new JButton(getImageIcon("/icons/pause_icon.png")); pause.setToolTipText("Pause"); pause.setBorderPainted(false); JButton size = new JButton(getImageIcon("/icons/size_icon.png")); size.setToolTipText("Set grid size"); size.setBorderPainted(false); JButton showGrid = new JButton(getImageIcon("/icons/grid_icon.png")); showGrid.setToolTipText("Enable/disable grid lines"); showGrid.setBorderPainted(false); JButton btRandom = new JButton(getImageIcon("/icons/dice_icon.png")); btRandom.setToolTipText("Fill randomly"); btRandom.setBorderPainted(false); JButton btAbout = new JButton(getImageIcon("/icons/about_icon.png")); btAbout.setToolTipText("About"); btAbout.setBorderPainted(false); toolBar.add(start); toolBar.add(next); toolBar.add(pause); toolBar.add(reset); toolBar.add(btRandom); toolBar.add(size); toolBar.add(showGrid); toolBar.add(new JSeparator(SwingConstants.VERTICAL)); toolBar.add(btAbout); frame.setJMenuBar(toolBar); Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); frame.setSize(screenSize); Grid grid = new Grid(80, 80); Envolver envolver = new Envolver(grid, new SimpleTransition()); /*grid.setValueAt(150, 150, State.Full); grid.setValueAt(152, 150, State.Full); grid.setValueAt(152, 151, State.Full); grid.setValueAt(154, 152, State.Full); grid.setValueAt(154, 153, State.Full); grid.setValueAt(154, 154, State.Full); grid.setValueAt(156, 153, State.Full); grid.setValueAt(156, 154, State.Full); grid.setValueAt(156, 155, State.Full); grid.setValueAt(157, 154, State.Full);*/ Random random = new Random(); for (int x = 0; x < grid.getWidth(); x++) { for (int y = 0; y < grid.getHeight(); y++) { if (random.nextDouble() <= 0.3125) { grid.setValueAt(x, y, State.Full); } } } GridPanel panel = new GridPanel(grid); JScrollPane scrollPane = new JScrollPane(panel); scrollPane.setPreferredSize(screenSize); // panel.setPreferredSize(screenSize); frame.setLayout(new FormLayout("2dlu, default:grow, 2dlu", "2dlu, default:grow, 2dlu")); frame.getContentPane().add(scrollPane, CC.xy(2, 2)); frame.setVisible(true); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); Runner runner = new Runner(envolver, frame); start.addActionListener(e -> runner.start()); pause.addActionListener(e -> runner.pause()); size.addActionListener(e -> new SizeDialog(grid, frame)); reset.addActionListener( e -> { runner.pause(); grid.init(grid.getWidth(), grid.getHeight()); frame.repaint(); }); btRandom.addActionListener( e -> { String result = JOptionPane.showInputDialog( null, "Choose the probability for an filled cell:", "Input", JOptionPane.PLAIN_MESSAGE); try { if (Double.parseDouble(result) <= 1.0 && Double.parseDouble(result) >= 0) { runner.pause(); grid.init(grid.getWidth(), grid.getHeight(), Double.parseDouble(result)); frame.repaint(); } } catch (NumberFormatException ex) { // ignore } }); showGrid.addActionListener( e -> { panel.setShowGrid(!panel.isShowGrid()); frame.repaint(); }); next.addActionListener( e -> { envolver.evolve(); frame.repaint(); }); btAbout.addActionListener( e -> { JOptionPane.showMessageDialog( null, "For more information about the rules\nlook to the corresponding wikipedia article.\nNote that we do not look at an infinite grid!\nA cell at the border of the grid has less neighbours than cells in the center.", "About", JOptionPane.INFORMATION_MESSAGE); }); }
// gui constructor public Gui() throws IOException { // sets frame text and features super("Doge Clicker 1.0"); this.setIconImage(new ImageIcon("Images//doge.jpg").getImage()); // initializes sound files Sounds.initialize(); // gui dimensions and features setSize(1000, 700); setResizable(false); setLayout(null); Container c = getContentPane(); c.setBackground(new Color(255, 255, 255)); setDefaultCloseOperation(EXIT_ON_CLOSE); // timer for doge per second run method runs every millisecond timer = new Timer(); timer.schedule(new RemindTask(), 1000, 10); // bolded title title = new JLabel("Doge Clicker v1.0"); title.setBounds(0, 0, getWidth(), 40); title.setFont(new Font("Comic Sans MS", Font.BOLD, 26)); title.setForeground(Color.white); title.setHorizontalAlignment(JLabel.CENTER); add(title); // reads news.txt to have import text to array String filePath = "Data\\news.txt"; BufferedReader fileIn = new BufferedReader(new FileReader(filePath)); for (int i = 0; i < line.length; i++) { // reads lines and saves until done reading if ((line[i] = fileIn.readLine()) != null) {} } fileIn.close(); // close file // read flavor text.txt to import text to array filePath = "Data\\flavourtext.txt"; fileIn = new BufferedReader(new FileReader(filePath)); for (int i = 0; i < flavourText.length; i++) { // reads lines until complety reading if ((flavourText[i] = fileIn.readLine()) != null) {} } fileIn.close(); // flavour label that pops up randomly when doge is clicked flavourClick = new JLabel("Wow! Such click!"); flavourClick.setBounds(400, 100, getWidth(), getHeight()); flavourClick.setFont(new Font("Comic Sans MS", Font.BOLD, 25)); flavourClick.setForeground(Color.white); flavourClick.setOpaque(false); add(flavourClick); // label for achievements achievementText = new JLabel("These are your achievements"); achievementText.setBounds(75, 2, getWidth(), 15); achievementText.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); achievementText.setForeground(Color.white); add(achievementText); // label for doge buying and click upgrades dogeProducers = new JLabel("Buy to make more doge"); dogeProducers.setBounds(50, 160, getWidth(), 40); dogeProducers.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); dogeProducers.setForeground(Color.white); add(dogeProducers); dogeClickers = new JLabel("Miscellaneous upgrades wow"); dogeClickers.setBounds(700, 160, getWidth(), 40); dogeClickers.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); dogeClickers.setForeground(Color.white); add(dogeClickers); // doge click button dogeClick = new JButton(new ImageIcon("Images/doge.jpg")); dogeClick.addActionListener(this); dogeClick.setBounds(450, 100, 100, 100); dogeClick.setOpaque(false); dogeClick.setBorder(BorderFactory.createLineBorder(Color.black)); dogeClick.setToolTipText("Each click gives you " + clickUpgrade + " doge. wow"); add(dogeClick); // click multiplier clickMultiplier = new JLabel(multiplier + "x"); clickMultiplier.setBounds(570, 120, getWidth(), 50); clickMultiplier.setFont(new Font("Comic Sans MS", Font.BOLD, 30)); clickMultiplier.setForeground(Color.white); add(clickMultiplier); // clicks per second indicator cpsIndicator = new JLabel(cps + " clicks per second"); cpsIndicator.setBounds(570, 150, getWidth(), 50); cpsIndicator.setFont(new Font("Comic Sans MS", Font.BOLD, 10)); cpsIndicator.setForeground(Color.white); add(cpsIndicator); // event indicator eventIndicator = new JLabel("Welcome to doge clicker!"); eventIndicator.setBounds(700, 530, getWidth(), 50); eventIndicator.setFont(new Font("Comic Sans MS", Font.BOLD, 15)); eventIndicator.setForeground(Color.white); add(eventIndicator); // states the num of doge and doge per second dogeCount = new JLabel("Doge: " + doge); dogeCount.setBounds(0, 0, getWidth(), 120); dogeCount.setFont(new Font("Comic Sans MS", Font.BOLD, 20)); dogeCount.setForeground(Color.white); dogeCount.setHorizontalAlignment(JLabel.CENTER); add(dogeCount); dogePerSecond = new JLabel("You get " + dps + " doge per second"); dogePerSecond.setBounds(0, 25, getWidth(), 120); dogePerSecond.setFont(new Font("Comic Sans MS", Font.BOLD, 11)); dogePerSecond.setForeground(Color.white); dogePerSecond.setHorizontalAlignment(JLabel.CENTER); add(dogePerSecond); dogeClicktext = new JLabel("Click for more doge"); dogeClicktext.setBounds(400, 185, 200, 50); dogeClicktext.setFont(new Font("Comic Sans MS", Font.BOLD, 13)); dogeClicktext.setForeground(Color.white); dogeClicktext.setHorizontalAlignment(JLabel.CENTER); add(dogeClicktext); // doge button testing button devButton = new JButton(new ImageIcon()); devButton.addActionListener(this); devButton.setBounds(0, 0, 50, 50); devButton.setToolTipText("Such Secret"); devButton.setOpaque(false); devButton.setContentAreaFilled(false); devButton.setBorderPainted(false); add(devButton); // options and save buttons options = new JButton(new ImageIcon("Images/option.png")); options.addActionListener(this); options.setBounds(900, 10, 70, 70); options.setOpaque(false); options.setBorder(BorderFactory.createLineBorder(Color.black)); options.setToolTipText("Go to options"); add(options); save = new JButton(new ImageIcon("Images/save.png")); save.addActionListener(this); save.setBounds(820, 10, 70, 70); save.setOpaque(false); save.setBorder(BorderFactory.createLineBorder(Color.black)); save.setToolTipText("Save a file"); add(save); open = new JButton(new ImageIcon("Images/open.png")); open.addActionListener(this); open.setBounds(740, 10, 70, 70); open.setOpaque(false); open.setBorder(BorderFactory.createLineBorder(Color.black)); open.setToolTipText("Open a file"); add(open); // news headline label that will move for (int i = 0; i < 3; i++) { newsHeadline[i] = new JLabel("Welcome to Doge clicker this is a news headline!"); newsHeadline[i].setBounds(-200 - (475 * i), 615, getWidth(), 40); newsHeadline[i].setFont(new Font("Comic Sans MS", Font.BOLD, 13)); newsHeadline[i].setForeground(Color.white); add(newsHeadline[i]); } // create all buttons and button stats and labels for producers for (int i = 0; i < MAX_UPGRADES; i++) { producerStats[i] = new Producers(i); producers[i] = new JButton(new ImageIcon(producerStats[i].getImage())); producers[i].addActionListener(this); producers[i].setOpaque(false); producers[i].setBorder(BorderFactory.createLineBorder(Color.black)); producers[i].setToolTipText( "Your " + producerStats[i].getButtonName() + " gives " + producerStats[i].getDogeProduction() * producerStats[i].getCount() + " doge per second"); producers[i].setBounds(0, 0, 70, 70); buyProducers[i] = new JLabel( "Buy " + producerStats[i].getButtonName() + " for " + producerStats[i].getCost() + " doge"); buyProducers[i].setBounds(0, 0, getWidth(), 100); buyProducers[i].setFont(new Font("Comic Sans MS", Font.PLAIN, 12)); buyProducers[i].setForeground(Color.white); buyDetails[i] = new JLabel( "You have: " + producerStats[i].getCount() + " " + producerStats[i].getButtonName()); buyDetails[i].setBounds(0, 0, getWidth(), 100); buyDetails[i].setFont(new Font("Comic Sans MS", Font.PLAIN, 12)); buyDetails[i].setForeground(Color.white); } // buttons and labels for click upgrades clickers for (int i = 0; i < MAX_CLICK; i++) { clickerStats[i] = new Clickers(i); clickers[i] = new JButton(new ImageIcon(clickerStats[i].getImage())); clickers[i].addActionListener(this); if (clickerStats[i].getClickMultiplier() == 1) { clickers[i].setToolTipText( "Buy this " + clickerStats[i].getButtonName() + " to get +" + clickerStats[i].getClickBonus() + " doge per click"); } else { clickers[i].setToolTipText( "Buy this " + clickerStats[i].getButtonName() + " to get x" + clickerStats[i].getClickMultiplier() + " doge per click"); } clickers[i].setOpaque(false); clickers[i].setBorder(BorderFactory.createLineBorder(Color.black)); clickers[i].setBounds(0, 0, 70, 70); buyClickers[i] = new JLabel( "Buy " + clickerStats[i].getButtonName() + " for " + clickerStats[i].getCost() + " doge"); buyClickers[i].setBounds(0, 0, getWidth(), 100); buyClickers[i].setFont(new Font("Comic Sans MS", Font.PLAIN, 12)); buyClickers[i].setForeground(Color.white); } // labels for achievements for (int i = 0; i < MAX_ACHIEVEMENTS; i++) { achievementStats[i] = new Achievements(i); achievements[i] = new JLabel(new ImageIcon(achievementStats[i].getImage())); achievements[i].setBorder(BorderFactory.createLineBorder(Color.black)); achievements[i].setToolTipText("Achievement: " + achievementStats[i].getButtonName()); achievements[i].setBounds(0, 0, 70, 70); } // JPanel containing achievements JPanel achievementPanel = new JPanel(); achievementPanel.setPreferredSize(new Dimension(350, 70)); achievementPanel.setLayout(null); achievementPanel.setOpaque(false); // JScrollpane containing JPanel for achievements JScrollPane achievementDisplay = new JScrollPane(); achievementDisplay.setViewportBorder(new LineBorder(Color.black)); achievementDisplay.setSize(280, 90); achievementDisplay.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); achievementDisplay.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); achievementDisplay.getVerticalScrollBar().setUnitIncrement(10); achievementDisplay.setLocation(50, 20); achievementDisplay.setOpaque(false); add(achievementDisplay); // adds the panel achievementDisplay.getViewport().add(achievementPanel); achievementDisplay.getViewport().setOpaque(false); // adds all achievements for (int i = 0; i < MAX_ACHIEVEMENTS; i++) { achievementPanel.add(achievements[i]); achievements[i].setLocation(0 + i * 70, 0); achievements[i].setVisible(false); } // jpanel containing upgrades for producers JPanel upgradePanel = new JPanel(); upgradePanel.setPreferredSize(new Dimension(350, 770)); upgradePanel.setLayout(null); upgradePanel.setOpaque(false); // Jscrollpane containing jpanel for producers JScrollPane producerUpgrades = new JScrollPane(); producerUpgrades.setViewportBorder(new LineBorder(Color.black)); producerUpgrades.setSize(350, 300); producerUpgrades.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); producerUpgrades.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); producerUpgrades.getVerticalScrollBar().setUnitIncrement(10); producerUpgrades.setLocation(0, 200); producerUpgrades.setOpaque(false); add(producerUpgrades); producerUpgrades.getViewport().setOpaque(false); producerUpgrades.getViewport().add(upgradePanel); // adds all upgrades for (int i = 0; i < MAX_UPGRADES; i++) { upgradePanel.add(producers[i]); producers[i].setLocation(0, (i) * 70); upgradePanel.add(buyProducers[i]); buyProducers[i].setLocation(90, (i * 70) - 35); upgradePanel.add(buyDetails[i]); buyDetails[i].setLocation(90, (i * 70) - 20); } // jpanel containing upgrades for clickers JPanel clickPanel = new JPanel(); clickPanel.setPreferredSize(new Dimension(350, 350)); clickPanel.setLayout(null); clickPanel.setOpaque(false); // Jscrollpane containing jpanel for clickers JScrollPane clickUpgrades = new JScrollPane(); clickUpgrades.setViewportBorder(new LineBorder(Color.black)); clickUpgrades.setSize(350, 300); clickUpgrades.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); clickUpgrades.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); clickUpgrades.getVerticalScrollBar().setUnitIncrement(10); clickUpgrades.setLocation(650, 200); clickUpgrades.setOpaque(false); add(clickUpgrades); clickUpgrades.getViewport().add(clickPanel); clickUpgrades.getViewport().setOpaque(false); // adds all click upgrades for (int i = 0; i < MAX_CLICK; i++) { clickPanel.add(clickers[i]); clickers[i].setLocation(0, (i) * 70); clickPanel.add(buyClickers[i]); buyClickers[i].setLocation(80, (i * 70) - 30); } // dancing snoop dog image JLabel snoop = new JLabel(new ImageIcon("Images//snoop.gif")); snoop.setBounds(450, 370, 150, 308); snoop.setOpaque(false); add(snoop); // background image JLabel background = new JLabel(new ImageIcon("Images//dogebackground.png")); background.setBounds(0, 0, 1000, 700); add(background); // makes everything above visible setVisible(true); // flavour click will remain invisible flavourClick.setVisible(false); // timer for news headline, runs every 20 milliseconds MyTimerTask task = new MyTimerTask(); Timer newsTimer = new Timer(); newsTimer.scheduleAtFixedRate(task, 0, 20); }
/** Install the Rotate-Button into the toolbar */ private void installRotateButton() { URL imgURL = ClassLoader.getSystemResource("ch/tbe/pics/rotate.gif"); ImageIcon rotateIcon = new ImageIcon(imgURL); rotate = new JButton(rotateIcon); rotate.setEnabled(false); rotatePanel = new JToolBar(); rotatePanel.setOrientation(1); rotatePanel.setLayout(new BorderLayout(0, 1)); rotateSlider = new JSlider(); rotateSlider.setMaximum(359); rotateSlider.setMinimum(0); rotateSlider.setMaximumSize(new Dimension(100, 100)); rotateSlider.setOrientation(1); Box box = Box.createVerticalBox(); sliderValue.setPreferredSize(new Dimension(30, 20)); rotateSlider.setAlignmentY(Component.TOP_ALIGNMENT); box.add(sliderValue); box.add(rotateSlider); sliderValue.setAlignmentY(Component.TOP_ALIGNMENT); rotatePanel.add(box, BorderLayout.NORTH); sliderValue.addFocusListener( new FocusListener() { private int oldValue = 0; public void focusGained(FocusEvent arg0) { oldValue = Integer.parseInt(sliderValue.getText()); } public void focusLost(FocusEvent arg0) { int newValue = 0; try { newValue = Integer.parseInt(sliderValue.getText()); } catch (Exception ex) { sliderValue.setText(Integer.toString(oldValue)); } if (newValue >= 0 && newValue <= 359) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rotateSlider.setValue(newValue); } else { sliderValue.setText(Integer.toString(oldValue)); } } }); rotateSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (board.getSelectionCount() == 1 && board.getSelectionCells()[0] instanceof ShapeItem) { sliderValue.setText(Integer.toString(rotateSlider.getValue())); ShapeItem s = (ShapeItem) board.getSelectionCells()[0]; board.removeItem(new ItemComponent[] {s}); s.setRotation(rotateSlider.getValue()); board.addItem(s); } } }); rotateSlider.addMouseListener( new MouseAdapter() { private int value; public void mousePressed(MouseEvent e) { value = rotateSlider.getValue(); } public void mouseReleased(MouseEvent e) { if (value != rotateSlider.getValue()) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rc.setRotation(value); } } }); rotate.setToolTipText(workingViewLabels.getString("rotate")); rotate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (board.getSelectionCount() == 1 && board.getSelectedItems()[0] instanceof ShapeItem) { rotateSlider.setValue(((ShapeItem) board.getSelectedItems()[0]).getRotation()); } rotatePanel.setVisible(!rotatePanel.isVisible()); showRotate = !showRotate; } }); rotate.setContentAreaFilled(false); rotate.setBorderPainted(false); toolbar.add(rotate); rotatePanel.setVisible(false); this.add(rotatePanel, BorderLayout.EAST); }