public SplitButton(final Icon icon) { mainText = new JLabel(icon); final JLabel menuIcon = new JLabel("\u25be"); super.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); super.add(mainText); super.add(Box.createRigidArea(new Dimension(GAP, 0))); super.add(new JSeparator(JSeparator.VERTICAL)); super.add(Box.createRigidArea(new Dimension(GAP, 0))); super.add(menuIcon); super.addMouseListener( new MouseAdapter() { public void mousePressed(final MouseEvent e) { if (!SplitButton.this.isEnabled()) return; final int x = e.getX(); final int w = e.getComponent().getWidth(); if (x >= (2 * w / 3)) { actionListenersEnabled = false; if (menu != null) { menu.show(e.getComponent(), e.getX(), e.getY()); } } else { actionListenersEnabled = true; } } }); }
public void addReadyToOrder() { JButton jb1 = new JButton(); JLabel l1 = new JLabel("Ready"); JLabel l2 = new JLabel("To"); JLabel l3 = new JLabel("Order"); l1.setFont(new Font(l1.getName(), Font.BOLD, 30)); l1.setHorizontalAlignment(SwingConstants.CENTER); l2.setFont(new Font(l2.getName(), Font.BOLD, 20)); l2.setHorizontalAlignment(SwingConstants.CENTER); l3.setFont(new Font(l3.getName(), Font.BOLD, 30)); l3.setHorizontalAlignment(SwingConstants.CENTER); jb1.addActionListener(new OrderListener()); jb1.setPreferredSize(new Dimension(150, 90)); jb1.setLayout(new GridLayout(3, 1)); jb1.add(l1); jb1.add(l2); jb1.add(l3); frame.add(jb1); }
public void addRequestWater() { JButton jb1 = new JButton(); JLabel l1 = new JLabel("Request"); JLabel l2 = new JLabel("Water"); l1.setFont(new Font(l1.getName(), Font.PLAIN, 30)); l1.setHorizontalAlignment(SwingConstants.CENTER); l2.setFont(new Font(l2.getName(), Font.PLAIN, 30)); l2.setHorizontalAlignment(SwingConstants.CENTER); jb1.addActionListener(new WaterListener()); jb1.setPreferredSize(new Dimension(150, 90)); jb1.setLayout(new GridLayout(2, 1)); jb1.add(l1); jb1.add(l2); frame.add(jb1); }
/** * Makes a JButton with the given icon and tooltop. If the icon cannot be loaded, then the text * will be used instead. * * <p>Adds this RenderFame as an actionListener. * * @return a shiny new JButton */ private JButton getProgressButton(final Action a, final String tip, final ImageIcon i) { MemProgressBar mem = new MemProgressBar(); mem.setMaximumSize(new Dimension(250, 32)); final JButton button = new JButton(a); // button.add(Box.createHorizontalGlue()); button.add(mem); button.setToolTipText(tip); button.setIcon(i); button.setFocusable(false); button.setPreferredSize(new Dimension(250, 32)); button.setMaximumSize(new Dimension(250, 32)); button.setBorder(new EmptyBorder(3, 3, 3, 3)); return button; }
public static JXPanel getDescription(CardView card, int width, int height) { JXPanel descriptionPanel = new JXPanel(); // descriptionPanel.setAlpha(.8f); descriptionPanel.setBounds(0, 0, width, height); descriptionPanel.setVisible(false); descriptionPanel.setLayout(null); // descriptionPanel.setBorder(BorderFactory.createLineBorder(Color.green)); JButton j = new JButton(""); j.setBounds(0, 0, width, height); j.setBackground(Color.black); j.setLayout(null); JLabel name = new JLabel("Wrath of God"); name.setBounds(5, 5, width - 90, 20); name.setForeground(Color.white); name.setFont(cardNameFont); // name.setBorder(BorderFactory.createLineBorder(Color.green)); j.add(name); JLabel cost = new JLabel("B R G W U"); cost.setBounds(width - 85, 5, 77, 20); cost.setForeground(Color.white); cost.setFont(cardNameFont); // cost.setBorder(BorderFactory.createLineBorder(Color.green)); cost.setHorizontalAlignment(SwingConstants.RIGHT); j.add(cost); JLabel type = new JLabel("Creature - Goblin Shaman"); type.setBounds(5, 70, width - 8, 20); type.setForeground(Color.white); type.setFont(cardNameFont); // type.setBorder(BorderFactory.createLineBorder(Color.green)); j.add(type); JLabel cardText = new JLabel(); cardText.setBounds(5, 100, width - 8, 260); cardText.setForeground(Color.white); cardText.setFont(cardNameFont); cardText.setVerticalAlignment(SwingConstants.TOP); // cardText.setBorder(new EtchedBorder()); j.add(cardText); name.setText(card.getName()); cost.setText(card.getManaCost().toString()); String typeText = ""; String delimiter = card.getCardTypes().size() > 1 ? " - " : ""; for (CardType t : card.getCardTypes()) { typeText += t; typeText += delimiter; delimiter = " "; // next delimiters are just spaces } type.setText(typeText); cardText.setText("<html>" + card.getRules() + "</html>"); if (CardUtil.isCreature(card)) { JLabel pt = new JLabel(card.getPower() + "/" + card.getToughness()); pt.setBounds(width - 50, height - 30, 40, 20); pt.setForeground(Color.white); pt.setFont(cardNameFont); pt.setHorizontalAlignment(JLabel.RIGHT); j.add(pt); } descriptionPanel.add(j); return descriptionPanel; }
public void run() { jframe = new JFrame("Address"); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.getContentPane().add(new JLabel("Address")); // JPanel Address = new JPanel(); Address.setLayout(new BoxLayout(Address, BoxLayout.Y_AXIS)); JPanel To_do = new JPanel(); To_do.setLayout(new BoxLayout(To_do, BoxLayout.Y_AXIS)); JPanel Search = new JPanel(); Search.setLayout(new BoxLayout(Search, BoxLayout.Y_AXIS)); // Menu bar for address book JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenu menu2 = new JMenu("Help"); JMenu menu3 = new JMenu("Contacts"); JMenu menu4 = new JMenu("To do list"); JMenu menu5 = new JMenu("About"); JMenu menu6 = new JMenu("Contacts"); bar.add(menu); bar.add(menu3); bar.add(menu4); bar.add(menu2); bar.add(menu5); /** ****Contacts tab***** */ JMenuItem menuitem = new JMenuItem("Add Contact"); menu3.add(menuitem); menuitem.addActionListener(this); menuitem.setActionCommand(ADDCONTACT); /*Sub directories*/ JMenuItem menuitem3 = new JMenuItem("View Address Book"); menu3.add(menuitem3); JMenu menuitem5 = new JMenu("Export Address Book"); JMenuItem menu22 = new JMenuItem("Export .txt file"); JMenuItem menu23 = new JMenuItem("Export .csv file"); menuitem5.add(menu22); menuitem5.add(menu23); menu3.add(menuitem5); // To do list tab JMenuItem menuitem2 = new JMenuItem("Add To Do Item"); menu4.add(menuitem2); JMenuItem menuitem4 = new JMenuItem("View To do List"); menu4.add(menuitem4); JMenu menuitem6 = new JMenu("Export To do List"); JMenuItem menu222 = new JMenuItem("Export .txt file"); JMenuItem menu233 = new JMenuItem("Export .csv file"); menuitem6.add(menu222); menuitem6.add(menu233); menu4.add(menuitem6); // File sub directory JMenu import_add = new JMenu("Import contacts"); JMenu import_todo = new JMenu(); JMenuItem import_format1 = new JMenuItem("Import .txt file"); JMenuItem import_format2 = new JMenuItem("Import .csv file"); import_add.add(import_format1); import_add.add(import_format2); menu.add(import_add); // To do sub directors JMenuItem import_format11 = new JMenuItem("Import .txt file"); JMenuItem import_format22 = new JMenuItem("Import .csv file"); JMenu menuitem9 = new JMenu("Import To do list"); menuitem9.add(import_format11); menuitem9.add(import_format22); menu.add(menuitem9); JMenuItem menuitem7 = new JMenuItem("Exit"); menu.add(menuitem7); menuitem7.addActionListener(this); menuitem7.setActionCommand(EXITCOMMAND); // Help Tab JMenuItem menuitem10 = new JMenuItem("Address Book"); menu2.add(menuitem10); JMenuItem menuitem11 = new JMenuItem("To do list"); menu2.add(menuitem11); JButton address = new JButton("Address Book"); address.setActionCommand(ADDRESS); address.addActionListener(this); Address.add(address); JButton to_do = new JButton("To do list"); to_do.setActionCommand(TASK); to_do.addActionListener(this); to_do.add(address); JButton search = new JButton("Search Contacts"); search.setActionCommand(SEARCH); search.addActionListener(this); Search.add(search); jframe.getContentPane().add(address, BorderLayout.LINE_START); jframe.getContentPane().add(to_do, BorderLayout.CENTER); jframe.getContentPane().add(search, BorderLayout.LINE_END); jframe.setJMenuBar(bar); jframe.setMinimumSize(new Dimension(300, 300)); jframe.setVisible(true); jframe.pack(); }
// добавление кнопок телефона public JPanel addFuncButtons() { // добавление кнопки Повтор final JButton RedialButton = new JButton("Повтор"); RedialButton.setPreferredSize(new Dimension(180, 90)); RedialButton.setFont(ButtonsFont); RedialButton.setEnabled(false); RedialButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { Call(Redial); } }); // добавление кнопки Позвонить URL urlCall = ClassLoader.getSystemResource("phone-green-icon.png"); CallButton = new JButton(new ImageIcon(urlCall)); // CallButton = new JButton("call"); CallButton.setPreferredSize(new Dimension(180, 90)); if (DisplayField.getText().isEmpty()) CallButton.setEnabled(false); else CallButton.setEnabled(true); CallButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { Call(DisplayField.getText()); RedialButton.setEnabled(true); } }); // добавление кнопки Очистить дисплей URL urlRemove = ClassLoader.getSystemResource("Banned-icon.png"); JButton RemoveButton = new JButton(new ImageIcon(urlRemove)); // JButton RemoveButton = new JButton("remove"); RemoveButton.setPreferredSize(new Dimension(180, 90)); RemoveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { DisplayField.setText(""); CallButton.setEnabled(false); } }); // добавление кнопки Перевести звонок RedirectButton = new JButton(); RedirectButton.setPreferredSize(new Dimension(180, 90)); RedirectButton.setLayout(new BorderLayout()); JLabel label1 = new JLabel("Перевести", JLabel.CENTER); JLabel label2 = new JLabel("звонок", JLabel.CENTER); label1.setFont(ButtonsFont); label2.setFont(ButtonsFont); RedirectButton.add(BorderLayout.NORTH, label1); RedirectButton.add(BorderLayout.CENTER, label2); RedirectButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { CallFrame.MakeFramesVisible(false); MainFrame.RedirectFirstPage.Layout(0); MainFrame.RedirectPanel.setVisible(true); } }); // добавление кнопки история звонков JButton ListButton = new JButton(); ListButton.setPreferredSize(new Dimension(180, 90)); ListButton.setMaximumSize(new Dimension(180, 90)); ListButton.setLayout(new BorderLayout()); label1 = new JLabel("История", JLabel.CENTER); label2 = new JLabel("звонков", JLabel.CENTER); label1.setFont(ButtonsFont); label2.setFont(ButtonsFont); ListButton.add(BorderLayout.NORTH, label1); ListButton.add(BorderLayout.CENTER, label2); ListButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ev) { listBox.setVisible(!listBox.isVisible()); } }); // прикрепление функциональных кнопок к одной панели JPanel panel = new JPanel(); panel.setMinimumSize(new Dimension(650, 200)); panel.add(RedialButton); panel.add(RedirectButton); panel.add(ListButton); panel.add(CallButton); panel.add(RemoveButton); return panel; }
private JButton getAcceptOfferButton(final String nick, CargoOffer co) { JButton acceptOfferButton = new JButton(); acceptOfferButton.setToolTipText("Zaakceptuj ofert\u0119"); CargoOffersLoadPanel loadPanel = new CargoOffersLoadPanel(); JPanel renderedPanel = new JPanel(); loadPanel.render(co, renderedPanel, 0); renderedPanel.setOpaque(false); CargoOffersUnloadPanel unloadPanel = new CargoOffersUnloadPanel(); JPanel renderedUnloadPanel = new JPanel(); unloadPanel.render(co, renderedUnloadPanel, 0); renderedUnloadPanel.setOpaque(false); CargoOffersSubmissionDatePanel submissionPanel = new CargoOffersSubmissionDatePanel(); JPanel renderedSubmissionDatePanel = new JPanel(); submissionPanel.render(co, renderedSubmissionDatePanel, 0); renderedSubmissionDatePanel.setOpaque(false); renderedSubmissionDatePanel.setOpaque(false); acceptOfferButton.setLayout(new FlowLayout()); acceptOfferButton.add(renderedPanel); acceptOfferButton.add(renderedUnloadPanel); acceptOfferButton.add(renderedSubmissionDatePanel); // dodatki wygladowe tego buttonu acceptOfferButton.setBorderPainted(false); acceptOfferButton.setContentAreaFilled(false); acceptOfferButton.setFocusPainted(false); acceptOfferButton.setOpaque(false); acceptOfferButton.setVerticalTextPosition(SwingConstants.CENTER); acceptOfferButton.setHorizontalTextPosition(SwingConstants.CENTER); acceptOfferButton.setIcon(SparkRes.getImageIcon(SparkRes.CARGO_AKCEPTACJA_OFERTY1)); acceptOfferButton.setRolloverIcon(SparkRes.getImageIcon(SparkRes.CARGO_AKCEPTACJA_OFERTY2)); acceptOfferButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); // koniec dodatkow acceptOfferButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String initiator = null; String initiated = null; initiator = SparkManager.getSessionManager().getUsername(); initiated = nick; CargoOffer co = getCargoOffer(); OfferAcceptance offerAcceptance = new OfferAcceptance(); offerAcceptance.setInitiator(initiator); offerAcceptance.setInitiated(initiated); offerAcceptance.setOfferId(co.getId()); CargoDataManager.getInstance().initiateOfferAcceptance(initiator, initiated, co); } }); return acceptOfferButton; }