public UpgradesPanel(ORUIManager orUIManager) { super(BoxLayout.Y_AXIS); this.orUIManager = orUIManager; preferredSize = new Dimension((int) Math.round(100 * (2 + Scale.getFontScale()) / 3), 200); setSize(preferredSize); setVisible(true); upgradePanel = new JPanel(); upgradePanel.setOpaque(true); upgradePanel.setBackground(Color.DARK_GRAY); upgradePanel.setBorder(border); upgradePanel.setLayout(new GridLayout(defaultNbPanelElements, 1)); scrollPane = new JScrollPane(upgradePanel); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setSize(getPreferredSize()); doneButton.setActionCommand("Done"); doneButton.setMnemonic(KeyEvent.VK_D); doneButton.addActionListener(this); cancelButton.setActionCommand("Cancel"); cancelButton.setMnemonic(KeyEvent.VK_C); cancelButton.addActionListener(this); add(scrollPane); }
public void setWidth(int width) { int height = 50; editorPane.setSize(width, 2000); try { height = (int) editorPane.modelToView(editorPane.getDocument().getLength() - 1).getY() + 25; } catch (BadLocationException e) { } editorPane.setSize(width, height); sp.setSize(width + 1, height + 1); sp.revalidate(); editorPane.revalidate(); cp.repaint(); }
// 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); }
public void initPanel() { // The panel uses an absolute layout. setLayout(null); // Name nameField = new JFormattedTextField(20); nameField.setEditable(false); addRow("Name", nameField); // Label labelField = new JTextField(20); labelField.addActionListener(this); labelField.addFocusListener(this); addRow("Label", labelField); // Help Text helpTextField = new JTextField(20); helpTextField.addActionListener(this); helpTextField.addFocusListener(this); addRow("Help Text", helpTextField); // Widget widgetBox = new JComboBox(humanizedWidgets); widgetBox.addActionListener(this); addRow("Type", widgetBox); // Value valueField = new JTextField(20); valueField.addActionListener(this); valueField.addFocusListener(this); addRow("Value", valueField); // Enable If enableIfField = new JTextField(20); enableIfField.addActionListener(this); enableIfField.addFocusListener(this); addRow("Enable If", enableIfField); // Bounding Method boundingMethodBox = new JComboBox(new String[] {"none", "soft", "hard"}); boundingMethodBox.addActionListener(this); addRow("Bounding", boundingMethodBox); // Minimum Value minimumValueCheck = new JCheckBox(); minimumValueCheck.addActionListener(this); minimumValueField = new JTextField(10); minimumValueField.addActionListener(this); minimumValueField.addFocusListener(this); JPanel minimumValuePanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); minimumValuePanel.add(minimumValueCheck); minimumValuePanel.add(minimumValueField); addRow("Minimum", minimumValuePanel); // Maximum Value maximumValueCheck = new JCheckBox(); maximumValueCheck.addActionListener(this); maximumValueField = new JTextField(10); maximumValueField.addActionListener(this); maximumValueField.addFocusListener(this); JPanel maximumValuePanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); maximumValuePanel.add(maximumValueCheck); maximumValuePanel.add(maximumValueField); addRow("Maximum", maximumValuePanel); // Display Level displayLevelBox = new JComboBox(new String[] {"hud", "detail", "hidden"}); displayLevelBox.addActionListener(this); addRow("Display Level", displayLevelBox); // Menu Items menuItemsTable = new JTable(new MenuItemsModel()); menuItemsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPanel tablePanel = new JPanel(new BorderLayout(5, 5)); JScrollPane tableScroll = new JScrollPane( menuItemsTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); tableScroll.setSize(200, 170); tableScroll.setPreferredSize(new Dimension(200, 170)); tableScroll.setMaximumSize(new Dimension(200, 170)); tableScroll.setMinimumSize(new Dimension(200, 170)); tablePanel.add(tableScroll, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); addButton = new JButton(new Icons.PlusIcon()); addButton.addActionListener(this); removeButton = new JButton(new Icons.MinusIcon()); removeButton.addActionListener(this); upButton = new JButton(new Icons.ArrowIcon(Icons.ArrowIcon.NORTH)); upButton.addActionListener(this); downButton = new JButton(new Icons.ArrowIcon(Icons.ArrowIcon.SOUTH)); downButton.addActionListener(this); buttonPanel.add(addButton); buttonPanel.add(removeButton); buttonPanel.add(upButton); buttonPanel.add(downButton); tablePanel.add(buttonPanel, BorderLayout.SOUTH); addRow("Menu Items", tablePanel); }
/** Sets the number of visible rows. */ public void setVisibleRows(int num) { int tableHeight = num * callStackTable.getRowHeight(); scrollPane.setSize(getTableWidth(), tableHeight + 3); setPreferredSize(new Dimension(getTableWidth(), tableHeight + 30)); setSize(getTableWidth(), tableHeight + 30); }