@SuppressWarnings("unused") public void mouseClicked(int button, int x, int y, int clickCount) { if ((x >= NEWGAME_X && x <= (NEWGAME_X + newGameImage.getWidth())) && (y >= NEWGAME_Y && y <= (NEWGAME_Y + newGameImage.getHeight()))) { selection = Game.NEWGAME_STATE; } else if ((x >= LOADGAME_X && x <= (LOADGAME_X + loadGameImage.getWidth())) && (y >= LOADGAME_Y && y <= (LOADGAME_Y + loadGameImage.getHeight()))) { selection = Game.LOADGAME_STATE; } else if (optionsActivated && (x >= OPTIONS_X && x <= (OPTIONS_X + optionsImage.getWidth())) && (y >= OPTIONS_Y && y <= (OPTIONS_Y + optionsImage.getHeight()))) { selection = Game.OPTIONSGAME_STATE; } else { int id = Save.getInstance().levelIdForPoint(x - MAP_X, y - MAP_Y); if (id > -1 && Save.getInstance().hasSaveLoaded()) { if (!Save.getInstance().hasUnlockedLevelWithID(id)) { mapErrorLabel.setText("Niveau pas encore debloque!"); } else { selection = Game.GAMEPLAY_STATE; levelSelection = id; mapErrorLabel.setText(""); } } } }
/** * @param data Matriisi pelaajien pisteistä. 3*15, jossa ensimmäinen sarake kertoo pisteen tyypin, * toinen ja kolmas ovat pelaajien pisteet * @throws FileNotFoundException */ public void loadScores(Object[][] data) throws FileNotFoundException { ArrayList<Integer> p1points = new ArrayList<Integer>(); ArrayList<Integer> p2points = new ArrayList<Integer>(); String p1sheet = "src/sheet1.txt"; String p2sheet = "src/sheet2.txt"; Save manager1 = new Save(p1sheet); Save manager2 = new Save(p2sheet); p1points = manager1.readFromFile(p1sheet); p2points = manager2.readFromFile(p2sheet); for (int i = 0; i < 15; i++) { data[i][1] = p1points.get(i); data[i][2] = p2points.get(i); } }
public DistributedTextEditor() { area1.setFont(new Font("Monospaced", Font.PLAIN, 12)); area2.setFont(new Font("Monospaced", Font.PLAIN, 12)); ((AbstractDocument) area1.getDocument()).setDocumentFilter(dec); area2.setEditable(false); Container content = getContentPane(); content.setLayout(new BoxLayout(content, BoxLayout.Y_AXIS)); JScrollPane scroll1 = new JScrollPane( area1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); content.add(scroll1, BorderLayout.CENTER); JScrollPane scroll2 = new JScrollPane( area2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); content.add(scroll2, BorderLayout.CENTER); content.add(ipaddress, BorderLayout.CENTER); content.add(portNumber, BorderLayout.CENTER); JMenuBar JMB = new JMenuBar(); setJMenuBar(JMB); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMB.add(file); JMB.add(edit); file.add(Listen); file.add(Connect); file.add(Disconnect); file.addSeparator(); file.add(Save); file.add(SaveAs); file.add(Quit); edit.add(Copy); edit.add(Paste); edit.getItem(0).setText("Copy"); edit.getItem(1).setText("Paste"); Save.setEnabled(false); SaveAs.setEnabled(false); Disconnect.setEnabled(false); setDefaultCloseOperation(EXIT_ON_CLOSE); pack(); area1.addKeyListener(k1); area1.addMouseListener(m1); setTitle("Disconnected"); setVisible(true); area1.insert("Welcome to Hjortehandlerne's distributed text editor. \n", 0); this.addWindowListener(w1); }
public void actionPerformed(ActionEvent e) { saveOld(); area.setText(""); currentFile = "Untitled"; setTitle(currentFile + " - CoreyTextEditor"); changed = false; Save.setEnabled(false); SaveAs.setEnabled(false); }
/** * @param p1points Pelaajan pisteet arraylistana * @param p2points -||- * @throws IOException * @author J Tallentaa pistelistan tekstitiedostoon muodossa *,*,*,*,... */ public void saveScores(Object[][] data) throws IOException { ArrayList<Integer> p1points = new ArrayList<Integer>(); // siirretään pisteet käsittelyä varten matriisista listoihin ArrayList<Integer> p2points = new ArrayList<Integer>(); for (int i = 0; i < 15; i++) { p1points.add((Integer) data[i][1]); p2points.add((Integer) data[i][2]); } String p1sheet = "src/sheet1.txt"; // osoitetaan tallennusolio kohti oikeaa tiedostoa, tallennetaan // src-kansioon txt-muodossa String p2sheet = "src/sheet2.txt"; Save manager1 = new Save(p1sheet); // molempia pelaajia edustaa oma tallennusolio Save manager2 = new Save(p2sheet); manager1.writeToFile(p1points); // kutsutaan tallennusmetodia molemmille pelaajille manager2.writeToFile(p2points); }
// saves public void checkSave(ArrayList<Save> saves, int i) { Save save = saves.get(i); if (x - width / 2 < save.getX() && x + width / 2 >= save.getX() && y - height / 2 < save.getY() && y + height / 2 > save.getY()) { startX = save.getSaveX(); startY = save.getSaveY(); } }
/** * The disconnect method will stop the eventreplayer, and send null to the other peers, to stop * their reading from their streams. The GUI-menu is updated appropriately. */ public void disconnect() { setTitle("Disconnected"); active = false; if (connected == true) { er.stopStreamToQueue(); ert.interrupt(); setDocumentFilter(null); connected = false; setLocked(false); } deregisterOnPort(); Disconnect.setEnabled(false); Connect.setEnabled(true); Listen.setEnabled(true); Save.setEnabled(true); SaveAs.setEnabled(true); }
// public void createTimers() // { // timers = new javax.swing.Timer[Wave.numMinions]; // javax.swing.Timer temp = new javax.swing.Timer(0, new Listener()); // for (int x = 0; x < Wave.numMinions; x++) // { // timers[x] = temp; // timers[x].setDelay(multiplier*10); // timers[x].start(); // multiplier++; // } // multiplier = 0; // } public void define() { room = new Room(); save = new Save(); store = new Store(); for (int i = 0; i < tileset_ground.length; i++) { tileset_ground[i] = new ImageIcon("tileset_ground.png").getImage(); tileset_ground[i] = createImage( new FilteredImageSource( tileset_ground[i].getSource(), new CropImageFilter(0, 32 * i, 32, 32))); } for (int i = 0; i < tileset_air.length; i++) { tileset_air[i] = new ImageIcon("tileset_air.png").getImage(); tileset_air[i] = createImage( new FilteredImageSource( tileset_air[i].getSource(), new CropImageFilter(0, 32 * i, 32, 32))); } save.loadSave(new File("save/mission.ajay")); }
@Override public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException { g.setColor(Color.black); // Top part backgroundImage.draw( -backgroundImage.getWidth() / 8, -backgroundImage.getHeight() / 8, 300, 800); titleImage.draw(TITLE_X, TITLE_Y); newGameImage.draw(NEWGAME_X, NEWGAME_Y); loadGameImage.draw(LOADGAME_X, LOADGAME_Y); if (MainMenuGameState.optionsActivated) { optionsImage.draw(OPTIONS_X, OPTIONS_Y); } // Map part mapImage.draw(MAP_X, MAP_Y, 800 - 2 * MAP_X, 600 - MAP_Y); Save s = Save.getInstance(); if (s.hasSaveLoaded()) { int[] ids = s.getAllIds(); for (int i = 0; i < ids.length; i++) { int[] mapLvl = s.mapPointForLevelID(ids[i]); if (mapLvl != null) { switch (s.getFinishedStateForLevelID(ids[i])) { case 0: mapLvlDefaultImage.draw(MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]); break; case 1: mapLvlUnlockedImage.draw(MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]); break; case 2: mapLvlFinishedImage.draw(MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]); break; case 3: mapLvlUnlockedFinishedImage.draw( MAP_X + mapLvl[0], MAP_Y + mapLvl[1], mapLvl[2], mapLvl[3]); break; default: break; } } } } display.render(gc, g); }
/** * This method is called from within the constructor to initialize the form. WARNING: Do NOT * modify this code. The content of this method is always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jPanel1 = new javax.swing.JPanel(); jPanel2 = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jLabel3 = new javax.swing.JLabel(); jLabel10 = new javax.swing.JLabel(); jLabel11 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); itemCombo = new javax.swing.JComboBox(); itemcode = new javax.swing.JTextField(); itemName = new javax.swing.JTextField(); supplierNa = new javax.swing.JComboBox(); brandCompany = new javax.swing.JComboBox(); openSto = new javax.swing.JTextField(); purchaseR = new javax.swing.JTextField(); sellR = new javax.swing.JTextField(); warranty = new javax.swing.JTextField(); reOrder = new javax.swing.JTextField(); jLabel12 = new javax.swing.JLabel(); Save = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); cancel = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jPanel3 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); Table = new javax.swing.JTable(); setClosable(true); jLabel4.setText("Item Category:"); jLabel2.setText("Item Code"); jLabel3.setText("Item Name:"); jLabel10.setText("Supplier Name:"); jLabel11.setText("Brand Company:"); jLabel5.setText("Opening Stock :"); jLabel6.setText("Purchase Rate:"); jLabel7.setText("Selling Rate:"); jLabel8.setText("Warranty:"); jLabel9.setText("Re-order Notification"); itemcode.addKeyListener( new java.awt.event.KeyAdapter() { public void keyPressed(java.awt.event.KeyEvent evt) { itemcodeKeyPressed(evt); } }); openSto.addKeyListener( new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { openStoKeyTyped(evt); } }); purchaseR.addKeyListener( new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { purchaseRKeyTyped(evt); } }); sellR.addKeyListener( new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { sellRKeyTyped(evt); } }); reOrder.addKeyListener( new java.awt.event.KeyAdapter() { public void keyTyped(java.awt.event.KeyEvent evt) { reOrderKeyTyped(evt); } }); jLabel12.setText("Search"); Save.setText("Add"); Save.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { SaveActionPerformed(evt); } }); jButton3.setText("Delete"); jButton3.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); cancel.setText("Clear"); cancel.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cancelActionPerformed(evt); } }); jButton2.setText("Update"); jButton2.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton1.setText("Get Data"); jButton1.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton4.setText("Exit"); jButton4.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel2Layout .createSequentialGroup() .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup( jPanel2Layout .createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jLabel10) .addComponent( jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel8, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(27, 27, 27) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(openSto) .addComponent( brandCompany, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( itemCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(itemcode) .addComponent(itemName) .addComponent( supplierNa, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(purchaseR) .addComponent(sellR) .addComponent(warranty) .addComponent( reOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 225, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent( jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup( jPanel2Layout .createSequentialGroup() .addContainerGap() .addComponent( Save, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(cancel) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent( jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); jPanel2Layout.setVerticalGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel2Layout .createSequentialGroup() .addContainerGap() .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( itemCombo, javax.swing.GroupLayout.DEFAULT_SIZE, 28, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( itemcode, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel12))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( itemName, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( supplierNa, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent( jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( brandCompany, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( openSto, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(5, 5, 5) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent( jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( purchaseR, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( sellR, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( warranty, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent( jLabel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent( reOrder, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(Save) .addComponent(cancel)) .addGroup( jPanel2Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton3) .addComponent(jButton2) .addComponent(jButton1) .addComponent(jButton4))) .addGap(22, 22, 22))); jPanel3.setBackground(new java.awt.Color(102, 102, 102)); jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jLabel1.setForeground(new java.awt.Color(255, 255, 255)); jLabel1.setText("Add Item"); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel3Layout .createSequentialGroup() .addGap(474, 474, 474) .addComponent( jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(532, Short.MAX_VALUE))); jPanel3Layout.setVerticalGroup( jPanel3Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel3Layout .createSequentialGroup() .addContainerGap() .addComponent( jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(20, Short.MAX_VALUE))); Table.setModel( new javax.swing.table.DefaultTableModel(new Object[][] {{}, {}, {}, {}}, new String[] {})); Table.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { TableMouseClicked(evt); } }); jScrollPane1.setViewportView(Table); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel1Layout .createSequentialGroup() .addGap(6, 6, 6) .addComponent( jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jScrollPane1)) .addComponent( jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); jPanel1Layout.setVerticalGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( jPanel1Layout .createSequentialGroup() .addComponent( jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup( jPanel1Layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 444, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent( jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(71, Short.MAX_VALUE))); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup( javax.swing.GroupLayout.Alignment.TRAILING, layout .createSequentialGroup() .addGap(0, 0, Short.MAX_VALUE) .addComponent( jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))); layout.setVerticalGroup( layout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent( jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)); pack(); } // </editor-fold>//GEN-END:initComponents
// action listeners public void actionPerformed(ActionEvent e) { // doge click button gives doge if (e.getSource() == dogeClick) { cps = cps + 1; Sounds.run("wow"); // increases size of button temporarily if (animation == 0) { dogeClick.setBounds(460, 110, 80, 80); dogeClick.setIcon(new ImageIcon("Images/dogeopen.jpg")); animation = 1; } else if (animation == 1) { dogeClick.setBounds(450, 100, 100, 100); dogeClick.setIcon(new ImageIcon("Images/doge.jpg")); animation = 0; } // adds doge accordingly and updates JLabel doge = doge + ((clickUpgrade) * clickMultiply) * multiplier; dogeCount.setText("Doge: " + doge); // randomize text flavourClick.setText(flavourText[(int) (Math.random() * 49)]); flavourClick.setBounds( (int) (Math.random() * (800)), (int) ((Math.random() * (401)) + 50), getWidth(), 50); flavourClick.setFont( new Font("Comic Sans MS", Font.BOLD, (int) ((Math.random() * (15)) + 15))); Color colour = Random.getRandomColour(); flavourClick.setForeground(colour); flavourClick.setVisible(true); } // for loop for all buttons for (int i = 0; i < MAX_UPGRADES; i++) { // updates button stats and count if (e.getSource() == producers[i] && doge >= producerStats[i].getCost()) { doge = doge - producerStats[i].getCost(); producers[i].setIcon(new ImageIcon("Images//bought.PNG")); producerStats[i].increaseCount(); producerStats[i].increaseCost(); producers[i].setToolTipText( "Your " + producerStats[i].getButtonName() + " gives " + producerStats[i].getDogeProduction() * producerStats[i].getCount() + " doge per second"); dps = dps + producerStats[i].getDogeProduction(); buyProducers[i].setText( "Buy " + producerStats[i].getButtonName() + " for " + producerStats[i].getCost() + " doge"); buyDetails[i].setText( "You have: " + producerStats[i].getCount() + " " + producerStats[i].getButtonName()); } } // updates click stats and count for (int i = 0; i < MAX_CLICK; i++) { if (e.getSource() == clickers[i] && doge >= clickerStats[i].getCost()) { doge = doge - clickerStats[i].getCost(); clickerStats[i].increaseCount(); clickUpgrade = clickUpgrade + clickerStats[i].getClickBonus(); clickMultiply = clickMultiply * clickerStats[i].getClickMultiplier(); dogeClick.setToolTipText( "Each click gives you " + (clickUpgrade) * clickMultiply + " doge. wow"); clickers[i].setVisible(false); buyClickers[i].setVisible(false); } } // secret developer button in corner if (e.getSource() == devButton) { doge = doge * 2; // plays Sandstorm by Darude Sounds.run("sandstorm"); } if (e.getSource() == options) { // opens options gui Options options = new Options(); } // saves current progress into save file if (e.getSource() == save) { // opens JOtionPane Sounds.run("save"); Save temp = new Save(); String name = JOptionPane.showInputDialog("What is the name of your save file?"); temp.createOutputFile("Save//" + name + ".txt"); String producerCount = ""; String clickCount = ""; String achievementCount = ""; // adds line of code for the amount of producers for (int i = 0; i < MAX_UPGRADES; i++) { producerCount = producerCount + producerStats[i].getCount() + "|"; } // adds line of code for the amount of clickers for (int i = 0; i < MAX_CLICK; i++) { // if bought write true if (clickerStats[i].getCount() != 0) { clickCount = clickCount + "t|"; } else { // if not bought write false clickCount = clickCount + "f|"; } } // adds a line of code for achievements for (int i = 0; i < MAX_ACHIEVEMENTS; i++) { // if possess write true if (achievementStats[i].getCount() != 0) { achievementCount = achievementCount + "t|"; } else { // if do not have write f achievementCount = achievementCount + "f|"; } } // add all lines to file temp.addInfo("" + doge); temp.addInfo("" + producerCount); temp.addInfo("" + clickCount); temp.addInfo("" + achievementCount); temp.closeOutputFile(); } // opens existing save file if (e.getSource() == open) { Save temp = new Save(); String name = JOptionPane.showInputDialog("What is the name of your save file?"); temp.openInputFile("Save//" + name + ".txt"); try { // counters to open save file int add = 0; String data = ""; int producerCount = 0; int clickCount = 0; int achievementCount = 0; // turn each line into char array doge = Long.parseLong(temp.getInfo()); char producerSave[] = temp.getInfo().toCharArray(); char clickSave[] = temp.getInfo().toCharArray(); char achievementSave[] = temp.getInfo().toCharArray(); // looks at producer line and adjusts values and resets Jlabel // text for (int i = 0; i < producerSave.length; i++) { if (producerSave[i] != '|') { data = data + Character.getNumericValue(producerSave[i]); } else { // updates data in producers add = Integer.parseInt(data); producerStats[producerCount].setCount(add); producerStats[producerCount].setCost( (int) (producerStats[producerCount].getCost() * (add * producerStats[producerCount].getCostIncrease()))); buyProducers[producerCount].setText( "Buy " + producerStats[producerCount].getButtonName() + " for " + producerStats[producerCount].getCost() + " doge"); buyDetails[producerCount].setText( "You have: " + producerStats[producerCount].getCount() + " " + producerStats[producerCount].getButtonName()); producers[producerCount].setToolTipText( "Your " + producerStats[producerCount].getButtonName() + " gives " + producerStats[producerCount].getDogeProduction() * producerStats[producerCount].getCount() + " doge per second"); dps = dps + (producerStats[producerCount].getDogeProduction() * producerStats[producerCount].getCount()); data = ""; producerCount++; add = 0; } } // reads clicker upgrades saves for (int i = 0; i < MAX_CLICK * 2; i++) { if (clickSave[i] == 't') { // updates data in clickers clickerStats[clickCount].setCount(1); clickUpgrade = (clickUpgrade + clickerStats[clickCount].getClickBonus()) * clickerStats[clickCount].getClickMultiplier(); dogeClick.setToolTipText("Each click gives you " + clickUpgrade + " doge. wow"); clickers[clickCount].setVisible(false); buyClickers[clickCount].setVisible(false); clickCount++; } else if (clickSave[i] == 'f') { clickCount++; } } // reads achievement lines for (int i = 0; i < MAX_ACHIEVEMENTS * 2; i++) { if (achievementSave[i] == 't') { // updates achievements achievementStats[achievementCount].setCount(1); achievements[achievementCount].setVisible(true); achievementCount++; } else if (achievementSave[i] == 'f') { achievementCount++; } } dogeCount.setText("Doge: " + doge); } catch (IOException e1) { // access invalid file e1.printStackTrace(); System.out.println("Invalid file!"); } // closes input file try { temp.closeInputFile(); } catch (IOException e1) { // access invalid file e1.printStackTrace(); System.out.println("Invalid file!"); } } }
public void actionPerformed(ActionEvent e) { saveOld(); area1.setText(""); resetArea2(); try { clientSocket = new Socket(ipaddress.getText(), Integer.parseInt(portNumber.getText())); Random r = new Random(); serverport = 10000 + r.nextInt(8999); // random port :D serverSocket = new ServerSocket(serverport); active = true; editor.setTitleToListen(); connected = true; ObjectOutputStream output = new ObjectOutputStream(clientSocket.getOutputStream()); ObjectInputStream input = new ObjectInputStream(clientSocket.getInputStream()); output.writeObject(new JoinNetworkRequest(serverport)); ConnectionData data = getConnectionData(clientSocket, input); lc = new LamportClock(data.getId()); lc.setMaxTime(data.getTs()); dec = new DocumentEventCapturer(lc, editor); er = new EventReplayer(editor, dec, lc); ert = new Thread(er); ert.start(); Peer peer = new Peer( editor, er, data.getHostId(), clientSocket, output, input, lc, clientSocket.getInetAddress().getHostAddress(), data.getPort()); dec.addPeer(peer); Thread thread = new Thread(peer); thread.start(); er.setAcknowledgements(data.getAcknowledgements()); er.setEventHistory(data.getEventHistory()); er.setCarets(data.getCarets()); er.addCaretPos(lc.getID(), 0); for (PeerWrapper p : data.getPeers()) { Socket socket; try { socket = connectToPeer(p.getIP(), p.getPort()); ObjectOutputStream outputStream = new ObjectOutputStream(socket.getOutputStream()); ObjectInputStream inputStream = new ObjectInputStream(socket.getInputStream()); outputStream.writeObject( new NewPeerDataRequest(lc.getID(), serverSocket.getLocalPort(), 0)); Peer newPeer = new Peer( editor, er, p.getId(), socket, outputStream, inputStream, lc, p.getIP(), p.getPort()); dec.addPeer(newPeer); Thread t = new Thread(newPeer); t.start(); } catch (IOException ex) { continue; } } Thread t1 = new Thread( new Runnable() { @Override public void run() { waitForConnection(); } }); t1.start(); area1.setText(data.getTextField()); area1.setCaretPosition(0); setDocumentFilter(dec); dec.sendObjectToAllPeers(new UnlockRequest(lc.getTimeStamp())); changed = false; Connect.setEnabled(false); Disconnect.setEnabled(true); Listen.setEnabled(false); Save.setEnabled(false); SaveAs.setEnabled(false); } catch (NumberFormatException | IOException e1) { setTitle("Unable to connect"); } }
public void actionPerformed(ActionEvent e) { saveOld(); final InetAddress local; active = true; try { local = InetAddress.getLocalHost(); Runnable server = new Runnable() { public void run() { serverport = Integer.parseInt(portNumber.getText()); int myID = getNewId(); registerOnPort(); editor.setTitleToListen(); clientSocket = waitForConnectionFromClient(); lc = new LamportClock(myID); area1.setText(""); resetArea2(); if (clientSocket != null) { listen = true; connected = true; dec = new DocumentEventCapturer(lc, editor); setDocumentFilter(dec); er = new EventReplayer(editor, dec, lc); er.updateCaretPos(myID, 0); ert = new Thread(er); ert.start(); try { ObjectOutputStream output = new ObjectOutputStream(clientSocket.getOutputStream()); ObjectInputStream input = new ObjectInputStream(clientSocket.getInputStream()); JoinNetworkRequest request = (JoinNetworkRequest) input.readObject(); int id = getNewId(); Peer peer = new Peer( editor, er, id, clientSocket, output, input, lc, clientSocket.getInetAddress().getHostAddress(), request.getPort()); ConnectionData cd = new ConnectionData( er.getEventHistory(), er.getAcknowledgements(), er.getCarets(), id, area1.getText(), lc.getTimeStamp(), lc.getID(), dec.getPeers(), serverSocket.getLocalPort()); dec.addPeer(peer); er.addCaretPos(id, 0); Thread t = new Thread(peer); t.start(); peer.writeObjectToStream(cd); } catch (IOException | ClassNotFoundException e) { e.printStackTrace(); } } waitForConnection(); } }; Thread serverThread = new Thread(server); serverThread.start(); } catch (UnknownHostException e1) { e1.printStackTrace(); } changed = false; Disconnect.setEnabled(true); Listen.setEnabled(false); Connect.setEnabled(false); Save.setEnabled(false); SaveAs.setEnabled(false); }
public void keyPressed(KeyEvent e) { changed = true; Save.setEnabled(true); SaveAs.setEnabled(true); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); adpt = new GalleryAdapter(this); pics = new Vector<Image>(); previews = (Gallery) findViewById(R.id.gallery1); Main = (ImageView) findViewById(R.id.PictureView); hist = (Histogram) findViewById(R.id.histogram); saturation = (SeekBar) findViewById(R.id.saturation); contrast = (SeekBar) findViewById(R.id.contrast); exposure = (SeekBar) findViewById(R.id.exposure); saveButton = (Button) findViewById(R.id.save); contrast.setProgress(50); exposure.setProgress(50); saturation.setProgress(100); handler = new UIHandler(Main, hist); tm = new ThreadManager(handler); save = new Save(); save.setContainer(Main); PinchyZoomy pz = new PinchyZoomy(); Main.setOnTouchListener(pz); Main.setDrawingCacheEnabled(true); Main.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_HIGH); File folder = new File("/sdcard"); for (int i = 0; i < folder.listFiles().length; i++) { String name = folder.listFiles()[i].getName(); if (folder.listFiles()[i].isFile()) { String extension = name.substring(name.length() - 3); if (extension.equals("NEF") || extension.equals("dng")) { Image temp = new Image(folder.listFiles()[i].getAbsolutePath()); pics.add(temp); } } } for (int i = 0; i < pics.size(); i++) { System.out.println("Pulling thumb for: " + pics.elementAt(i).path); adpt.addImage(pics.elementAt(i).getThumb()); } previews.setAdapter(adpt); previews.setSpacing(3); previews.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Main.setImageBitmap(adpt.getItemAt(position)); Main.setAlpha(100); if (current != null) current.free(); current = pics.elementAt(position); handler.setImage(current); tm.pic = current; save.setImage(current); contrast.setProgress(50); exposure.setProgress(50); saturation.setProgress(100); LoadImageThread t = new LoadImageThread(current, handler); t.start(); } }); saturation.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) { if (current.colors != null) tm.setSaturation(saturation.getProgress()); } @Override public void onStartTrackingTouch(SeekBar arg0) {} @Override public void onStopTrackingTouch(SeekBar arg0) {} }); contrast.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (current.colors != null) tm.setContrast(contrast.getProgress()); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); exposure.setOnSeekBarChangeListener( new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (current.colors != null) tm.setExposure(exposure.getProgress()); } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } }); saveButton.setOnClickListener(save); }
/** Constructor to create the frame and its components */ public CoreyTextEditor() { // Create a scroll pane area.setFont(new Font("Monospaced", Font.PLAIN, 12)); JScrollPane scroll = new JScrollPane( area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); add(scroll, BorderLayout.CENTER); // Adds the system default look and feel try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) { e.printStackTrace(); } // Create a menu bar JMenuBar JMB = new JMenuBar(); setJMenuBar(JMB); JMenu file = new JMenu("File"); JMenu edit = new JMenu("Edit"); JMB.add(file); JMB.add(edit); // Finishing our menu bar file.add(New); file.add(Open); file.add(Save); file.add(SaveAs); file.addSeparator(); file.add(Quit); edit.add(Cut); edit.add(Copy); edit.add(Paste); edit.getItem(0).setText("Cut"); edit.getItem(0).setIcon(new ImageIcon("cut.gif")); edit.getItem(1).setText("Copy"); edit.getItem(1).setIcon(new ImageIcon("copy.gif")); edit.getItem(2).setText("Paste"); edit.getItem(2).setIcon(new ImageIcon("paste.gif")); // Time to make a toolbar! JToolBar tool = new JToolBar(); add(tool, BorderLayout.NORTH); tool.add(New); tool.add(Open); tool.add(Save); tool.addSeparator(); JButton cut = tool.add(Cut); JButton cop = tool.add(Copy); JButton pas = tool.add(Paste); cut.setText(null); cut.setIcon(new ImageIcon("cut.gif")); cop.setText(null); cop.setIcon(new ImageIcon("copy.gif")); pas.setText(null); pas.setIcon(new ImageIcon("paste.gif")); Save.setEnabled(false); SaveAs.setEnabled(false); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); pack(); /* KeyListener to change Save and SaveAs */ KeyListener k1 = new KeyAdapter() { public void keyPressed(KeyEvent e) { changed = true; Save.setEnabled(true); SaveAs.setEnabled(true); } }; area.addKeyListener(k1); setTitle(currentFile + " - CoreyTextEditor"); setVisible(true); }