id
stringlengths
36
36
text
stringlengths
1
1.25M
d0119f35-6eac-4e24-8a6b-f6dd794623af
@Override protected Money clone() throws CloneNotSupportedException { return new Money(getDollars(), getCents(), isNegative); }
4d88f0ba-576a-44af-b5ef-c7a76c4661f1
@Override public int compareTo(Money o) { return (int) (getExpandedLong(this) - getExpandedLong(o)); }
2a10fc96-b7c0-4ae0-9d10-b3f3b421ec81
public static Money random() { return new Money(random.nextInt(500), random.nextInt(), false); }
c33d1d22-4b0a-4d1f-aa14-b1d80b992da0
private MoneyUtils() { }
ec2f1964-8716-4dee-90e1-62f2437561cf
public static Map<Money, Integer> getChange(Money money) throws InterruptedException { Map<Money, Integer> change = new HashMap<>(); for (Money m : Money.DENOMINATIONS_HIGH_TO_LOW) { change.put(m, 0); while (money.compareTo(m) >= 0) { int currentVal = change.get(m); System.out.println("Another " + m + " used up!"); change.put(m, currentVal + 1); money = Money.add(money, m.negateTemporarily()); System.out.println("Money now: " + money + "\n"); } } return change; }
f799849b-c20b-426e-ad00-9c2cfd71bd5e
public static void main(String[] args) throws InterruptedException { Money money = Money.random(); System.out.println(money + "\n-------------"); Map<Money, Integer> change = MoneyUtils.getChange(money); for (Money m : Money.DENOMINATIONS_HIGH_TO_LOW) { System.out.println(m + ": " + change.get(m)); } }
afb762b3-3039-487d-adaa-07029e6e8b95
public DatePanel(final LocalDate d, final TransactionPanel tp){ monthComboBox = new JComboBox<>(formattedMonths); dayComboBox = new JComboBox<>(DayComboBoxModel.get30DayComboBoxModel()); yearComboBox = new JComboBox<>(YearComboBoxModel.getDefault()); getMonthComboBox().setSelectedIndex(d.getMonthValue() - 1); YearComboBoxModel.getDefault(); yearComboBox.setSelectedIndex(d.getYear() - YearComboBoxModel.getStartingNumber()); updateDayComboBox(); dayComboBox.setSelectedIndex(d.getDayOfMonth() - 1); addListeners(); add(getMonthComboBox()); add(dayComboBox); add(yearComboBox); transactionPanel = tp; }
30cfad9a-b3ef-42bf-a3b8-ce818a71dbdd
public DatePanel(final TransactionPanel tp){ this(LocalDate.now(), tp); }
93d335d5-fd91-41c3-b78c-1dc81a4cb74f
@Override public void actionPerformed(final ActionEvent e) { int year = (int) yearComboBox.getSelectedItem(); int day = (int) dayComboBox.getSelectedItem(); Month month = Month.valueOf(monthComboBox.getSelectedItem().toString().toUpperCase()); LocalDate d = LocalDate.of(year, month, day); getTransactionPanel().getTransaction().setDate(d); Serializer.saveState(); }
7ba1db44-a8f2-460c-8434-b5bad695eec1
public JComboBox<String> getMonthComboBox() { return monthComboBox; }
ab9691d0-2763-478a-86c2-7b7a0a25f42f
public TransactionPanel getTransactionPanel() { return transactionPanel; }
c21ded98-4b5d-4ba1-ba28-cc6ec7a74f93
private void addListeners() { getMonthComboBox().addActionListener(e -> updateDayComboBox()); yearComboBox.addActionListener(e -> updateDayComboBox()); dayComboBox.addActionListener(this); // yearComboBox.addActionListener(this); }
55b03c50-fc1f-4a18-b3d1-0ef14ece2be5
private void updateDayComboBox() { int day = (int) dayComboBox.getSelectedItem(); Month m = Month.of(getMonthComboBox().getSelectedIndex() + 1); int year = (int) yearComboBox.getSelectedItem(); boolean leap = false; if (year % 4 == 0) { leap = !leap; } int daysInMonth; switch (m) { case JANUARY: case MARCH: case MAY: case JULY: case AUGUST: case OCTOBER: case DECEMBER: daysInMonth = 31; break; case APRIL: case JUNE: case SEPTEMBER: case NOVEMBER: daysInMonth = 30; break; case FEBRUARY: if (leap) { daysInMonth = 29; } else { daysInMonth = 28; } break; default: daysInMonth = -1; } dayComboBox.setModel(DayComboBoxModel.getCorrectModel(daysInMonth)); if (day > daysInMonth) { day = daysInMonth; } dayComboBox.setSelectedItem(day); }
c4d6f24d-566a-42b3-a65e-b142c647afd8
public static YearComboBoxModel getDefault() { YearComboBoxModel d = new YearComboBoxModel(); for (int i = 1900; i <= 2100; i++) { d.addElement(i); } return d; }
9150c0be-d4b5-4aea-88cf-2125a1d190cb
public static int getStartingNumber() { return 1900; }
68e3588a-cf50-4932-aef1-017756e3bd8a
public static DayComboBoxModel get28DayComboBoxModel() { DayComboBoxModel tmp = new DayComboBoxModel(); for (int i = 1; i <= 28; i++) { tmp.addElement(i); } return tmp; }
ee2d4525-baeb-4602-895e-e468462b15fc
public static DayComboBoxModel get29DayComboBoxModel() { DayComboBoxModel tmp = new DayComboBoxModel(); for (int i = 1; i <= 29; i++) { tmp.addElement(i); } return tmp; }
3b9e0cd8-57ff-456b-b1a6-13d9c144c3f8
public static DayComboBoxModel get30DayComboBoxModel() { DayComboBoxModel tmp = new DayComboBoxModel(); for (int i = 1; i <= 30; i++) { tmp.addElement(i); } return tmp; }
2e8620d3-e11f-4fa8-a2cc-12ed8e0f7558
public static DayComboBoxModel get31DayComboBoxModel() { DayComboBoxModel tmp = new DayComboBoxModel(); for (int i = 1; i <= 31; i++) { tmp.addElement(i); } return tmp; }
9edb5ef6-c7ab-4bbe-b422-4bb5d617b66e
public static DayComboBoxModel getCorrectModel(final int daysInMonth) { switch (daysInMonth) { case 28: return get28DayComboBoxModel(); case 29: return get29DayComboBoxModel(); case 30: return get30DayComboBoxModel(); case 31: return get31DayComboBoxModel(); } throw new Error(); }
f6277ed4-fbf9-417c-9da8-e499a1ca28a8
public Money(){ this(0, 0, false); }
37e60163-6709-48dc-891a-d3d57d3fe7a6
public Money(long dollars, int cents, final boolean negative){ isNegative = negative; // Takes Absolute Value of dollars dollars = Math.abs(dollars); cents = Math.abs(cents); if (cents > 100) { // Rounds cents StringBuilder b = new StringBuilder(); String s = cents + ""; b.append(s.charAt(0)); b.append(s.charAt(1)); int i = Integer.parseInt(b.toString()); if (s.charAt(2) - '0' >= 5) { i++; } if (i == 100) { i = 0; dollars++; } this.cents = i; } else { this.cents = cents; } this.dollars = dollars; }
7acd17e0-34f1-41bb-a855-27a0a1c574b8
public static Money add(final Money first, final Money... varArgs) { long sum = 0; sum += getExpandedLong(first); for (Money m : varArgs) { sum += getExpandedLong(m); } return parseMoney(sum); }
3ab705df-112f-40cd-b62e-c5ab8f4fdaa4
public static long getExpandedLong(final Money m) { long raw = m.getDollars() * 100 + m.getCents(); if (m.isNegative) { raw *= -1; } return raw; }
89cce270-358c-4bd8-a7bf-918f8366baa5
public static Money parseMoney(final long longAmt) { boolean neg = false; if (longAmt < 0) { neg = true; } return new Money(longAmt / 100, (int) (longAmt % 100), neg); }
6d140b29-7bf2-4b56-b8f8-bb83afd79584
public static Money parseMoney(String inputString) { long dollars; int cents; int numOfNegs = 0; boolean neg; for (char c : inputString.toCharArray()) { if (c == '-') { numOfNegs++; } } if (numOfNegs % 2 == 0) { neg = false; } else { neg = true; } inputString = inputString.replaceAll("[^0-9.]+", ""); String[] listOfNumbersString; if (inputString.contains(".") && !inputString.substring(inputString.indexOf(".") + 1).equals("")) { listOfNumbersString = inputString.split("\\."); dollars = Long.parseLong(listOfNumbersString[0]); cents = Integer.parseInt(listOfNumbersString[1]); } else { inputString = inputString.replaceAll("\\.", ""); dollars = Long.parseLong(inputString); cents = 0; } return new Money(dollars, cents, neg); }
7c72dd3b-8134-4d51-9960-ee518516b568
@Override public boolean equals(final Object o) { if (o == null || !(o instanceof Money)) { return false; } Money m = (Money) o; if (dollars != m.getDollars() || cents != m.getCents() || isNegative != m.isNegative) { return false; } else { return true; } }
ca98d773-8c0b-49d7-89f6-893932678198
public int getCents() { return cents; }
0b186bd6-9fc1-4435-880b-bb3433e486f7
public long getDollars() { return dollars; }
d6de0073-e3b3-4428-b3f8-00420db0da17
@Override public int hashCode() { int hash = Long.valueOf(dollars).hashCode() * 9 + Integer.valueOf(cents).hashCode(); if (isNegative) { hash *= -1; } return hash; }
985a716f-5b73-4cf7-9e73-0187ec6d03f8
public Money negate() { isNegative = !isNegative; return this; }
4a355fbe-e0c5-42ad-af57-3e8156b5ba06
public Money negateTmp() { return new Money(dollars, cents, !isNegative); }
00008184-10ea-4a26-8314-ac610ee7d26d
@Override public String toString() { StringBuilder b = new StringBuilder(); if (isNegative) { b.append("-"); } b.append("$"); b.append(getDollars()); b.append("."); if (getCents() < 10) { b.append("0"); } b.append(getCents()); return b.toString(); }
16a32124-f719-4b8b-8504-d6a310ec96a3
@Override protected Money clone() throws CloneNotSupportedException { return new Money(getDollars(), getCents(), isNegative); }
ac0cc818-dcad-40b4-ba2e-88a6b3332309
public TransactionList(){ super(); balance = Money.ZERO; }
b529771c-c00b-46c2-8bd4-4471d88261cb
public TransactionList(final Money initialBalance){ super(); balance = initialBalance; }
dcb04537-cba0-462f-b3a7-0de1725b7355
@Override public boolean add(final Transaction t) { if (t.isDeposit()) { balance = Money.add(balance, t.getMoney()); } else { balance = Money.add(balance, t.getMoney().negateTmp()); } return super.add(t); }
3e769833-87ed-4ead-9920-a9fef06c544a
public Money getBalance() { return balance; }
b0c328d6-60c2-45ce-89e5-f7923e178a87
public Transaction getByID(final int ID) { for (Transaction t : this) { if (t.getID() == ID) { return t; } } return null; }
4b041c6e-ac69-4136-bdf6-0f3368bebc7e
public void removeTransaction(final int ID) { for (int i = 0; i < size(); i++) { if (get(i).getID() == ID) { remove(i); break; } } }
b5311107-618d-4ce7-bf2c-0fddb45eb648
@Override public String toString() { StringBuilder b = new StringBuilder(); for (Transaction t : this) { b.append(t.getDate()); b.append(": "); b.append(t.getType()); b.append(" "); b.append(t.getMoney()); b.append(": "); b.append(t.getMemo()); b.append("\n"); } return b.toString(); }
aa10bb7a-019e-496b-b2a0-306daa455729
public void transact(final Transaction t) { if (t.isBoring()) { System.err.println("Transaction is not unique!"); } else { this.add(t); Serializer.saveState(this); System.out.println(t); } }
c67594ee-e5c1-4998-8035-e16f70d37340
private Serializer(){}
dbf3bcdf-1b09-4b09-a1b4-b7481354b2e2
public static void clearEntries(final TransactionList t) { serializedFile.delete(); t.clear(); Transaction.setCurrentIndexForID(0); }
601691a8-b6fd-46a4-bfa3-60b14942d761
public static TransactionList getInstance() { try (ObjectInputStream is = new ObjectInputStream(new FileInputStream(serializedFile));) { TransactionList l = (TransactionList) is.readObject(); if (l != null) { System.out.println("READ FROM FILE"); for (Transaction t : l) { System.out.print(t); } } Integer i = is.readInt(); System.out.println("Starting from index " + i); Transaction.setCurrentIndexForID(i); return l; } catch (InvalidClassException e) { e.printStackTrace(); } catch (FileNotFoundException e) { System.err.println("File not Found. Creating new."); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return new TransactionList(); }
b4b96f7d-bfb7-4ca2-8b15-7bfdba3a4711
public static void saveState() { TransactionList list = new TransactionList(); for (TransactionPanel t : MainFrame.getTransactionPanelList()) { list.add(t.getTransaction()); } new Thread(new Runnable(){ @Override public void run() { Serializer.saveState(list); System.out.println("STATE SAVED"); } }).start(); }
590492a1-90b4-403a-aba7-6ba011bb71cc
@Override public void run() { Serializer.saveState(list); System.out.println("STATE SAVED"); }
1862d9fd-3da7-46cc-8bb2-8f3a40cd11d2
protected static File getSerializedFile() { return serializedFile; }
2098559d-e5d6-42aa-8fbd-c1c0ef203210
protected static void saveState(final TransactionList l) { try (ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream(getSerializedFile()));) { getSerializedFile().createNewFile(); os.writeObject(l); os.writeInt(Transaction.getCurrentIndexForID()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
0f5d41ed-a7aa-4c32-88a6-d85f9889b238
public Transaction(){ ID = idCount; idCount++; transactionType = Type.DEPOSIT; money = new Money(0, 0, false); memo = ""; date = LocalDate.now(); }
71b662da-cb40-4d64-ae54-0e24a2d58f71
public Transaction(final boolean isDeposit, final Money m, final String memo, final LocalDate date){ ID = idCount; System.out.println("Creating new Transaction with ID: " + idCount); idCount++; if (isDeposit) { transactionType = Type.DEPOSIT; } else { transactionType = Type.WITHDRAWAL; } money = m; this.memo = memo; this.date = date; }
f04b3b30-9814-44af-b927-29f8d7c7b27a
public static Integer getCurrentIndexForID() { return idCount; }
99cc14e3-bc4d-497c-835f-58c40b71dddc
public static void setCurrentIndexForID(final Integer currentIndex) { idCount = currentIndex; }
61f4fed3-a9cb-4e2d-9159-84fe7dba5320
@Override public boolean equals(final Object obj) { if (obj == null || obj.getClass() != Transaction.class) { return false; } Transaction t = (Transaction) obj; if (transactionType != t.getType() || !money.equals(t.getMoney()) || !memo.equals(t.getMemo())) { return false; } return true; }
5645182f-f393-42fb-8fdf-eaf3f28671aa
public LocalDate getDate() { return date; }
fdf691e9-b986-486e-9ca1-a3a6c3482b06
public int getID() { return ID; }
55c00f52-ffa1-4529-845c-174a57347faa
public String getMemo() { return memo; }
7a44a1ab-115b-4f42-b231-23e57d31334d
public Money getMoney() { return money; }
c951b3bd-7e5e-494a-b666-2f10ef168b30
public Type getType() { return transactionType; }
4b9dbb80-4cd0-4465-98eb-fa3ff0d4cdfb
@Override public int hashCode() { int hash = money.hashCode(); if (transactionType == Type.DEPOSIT) { hash = hash * 31 + 1; } else { hash = hash * 31 + 0; } hash *= 31 + memo.hashCode(); return hash; }
1b639b70-da32-411d-aaf5-e8e53f6ae198
public boolean isBoring() { if (money.equals(Money.ZERO)) { return true; } else { return false; } }
0648bb6f-4183-45da-8628-2c5a53731cba
public boolean isDeposit() { if (transactionType == Type.DEPOSIT) { return true; } else { return false; } }
459aa737-21d3-4eff-926f-915b0404874f
public void setDate(final LocalDate d) { date = d; }
e1632636-2cb0-467b-b2ff-7fc824f2a7ef
public void setMemo(final String m) { memo = m; }
c54e79f6-35de-4678-9e5e-ea087c1a5884
public void setMoney(final Money m) { money = m; }
0ce74344-756d-4386-9213-0fb21dca1d2a
public void setType(final Type t) { transactionType = t; }
88184de4-3fea-4864-b2d9-17743dada900
@Override public String toString() { StringBuilder b = new StringBuilder(); b.append(ID + " - " + date.format(DateTimeFormatter.ofPattern("d MMM uuuu")) + ": " + transactionType.toString().substring(0, 1) + " " + money.toString().substring(1) + "\n"); return b.toString(); }
e3e68637-2cfc-4a80-ad85-3edca1d24620
public TransactionPanel(final MainFrame frame, final Transaction transaction){ super(); if (TransactionPanel.frame == null) { TransactionPanel.frame = frame; } this.transaction = transaction; radioButtonPanel = new JPanel(); radioButtonPanel.setLayout(new BoxLayout(radioButtonPanel, BoxLayout.Y_AXIS)); depositRadioButton = new JRadioButton("Deposit"); depositRadioButton.addActionListener(this); withdrawalRadioButton = new JRadioButton("Withdrawal"); withdrawalRadioButton.addActionListener(this); buttonGroup = new ButtonGroup(); buttonGroup.add(depositRadioButton); buttonGroup.add(withdrawalRadioButton); if (transaction.isDeposit()) { depositRadioButton.setSelected(true); } else { withdrawalRadioButton.setSelected(true); } radioButtonPanel.add(depositRadioButton); radioButtonPanel.add(withdrawalRadioButton); moneyField = new JTextField(5); moneyField.setText(transaction.getMoney().toString()); moneyField.addFocusListener(this); memoField = new JTextField(10); memoField.setText(transaction.getMemo()); memoField.addFocusListener(this); memoField.addKeyListener(new KeyListener(){ @Override public void keyPressed(final KeyEvent e) { getTransaction().setMemo(getMemoField().getText()); Serializer.saveState(); } @Override public void keyReleased(final KeyEvent e) {} @Override public void keyTyped(final KeyEvent e) {} }); datePanel = new DatePanel(transaction.getDate(), this); deleteButton = new JButton("x"); deleteButton.setPreferredSize(new Dimension(25, 25)); deleteButton.addActionListener(this); add(radioButtonPanel); add(moneyField); add(datePanel); add(memoField); add(deleteButton); }
e65276be-a974-45ff-93d3-b8463a27b812
@Override public void keyPressed(final KeyEvent e) { getTransaction().setMemo(getMemoField().getText()); Serializer.saveState(); }
2265ef79-cb64-415b-9fe7-34f0aa7eec4f
@Override public void keyReleased(final KeyEvent e) {}
5ee663c2-9493-4763-bac4-cbade914f704
@Override public void keyTyped(final KeyEvent e) {}
ecbe4f4b-8405-48ea-bf09-3ccebeb04bf0
public static MainFrame getMainFrame() { return frame; }
55e386f8-31f3-468f-aec9-f7e3ac394c78
@Override public void actionPerformed(final ActionEvent e) { Object source = e.getSource(); if (source == getDepositRadioButton()) { getTransaction().setType(Type.DEPOSIT); } else if (source == getWithdrawalRadioButton()) { getTransaction().setType(Type.WITHDRAWAL); } else if (source == getDeleteButton()) { getMainFrame().removeTransactionByID(getTransaction().getID()); } Serializer.saveState(); getMainFrame().updateBalance(); }
55785976-a8d2-4469-9705-c9def7ce282b
@Override public void focusGained(final FocusEvent e) {}
ac8bbee5-c542-4dae-835a-89c733425c31
@Override public void focusLost(final FocusEvent e) { Object source = e.getSource(); if (source == getMoneyField()) { Money m = Money.parseMoney(getMoneyField().getText()); getMoneyField().setText(m.toString()); getTransaction().setMoney(m); getMainFrame().updateBalance(); } else if (source == getMemoField()) { getTransaction().setMemo(getMemoField().getText()); } Serializer.saveState(); }
dbb6dada-6b14-4964-a83c-27231cbf4d97
public Transaction getTransaction() { return transaction; }
05d4e970-9c8f-4bc0-9a8f-5b429c96a8cb
protected DatePanel getDatePanel() { return datePanel; }
9ba19fcb-8460-4e1b-ab52-ebe155d634af
protected JButton getDeleteButton() { return deleteButton; }
b9e0456f-e29e-4e17-8cfa-300ca88284d0
protected JRadioButton getDepositRadioButton() { return depositRadioButton; }
ff9016ee-7aec-484b-a11c-920b9296db91
protected JTextField getMemoField() { return memoField; }
06e39b97-72d5-4f9a-a379-1ffa65e7ae48
protected JTextField getMoneyField() { return moneyField; }
fde97ca9-0570-4ff8-b799-0c643673abb4
protected JPanel getRadioButtonPanel() { return radioButtonPanel; }
8e719007-d5a1-4f64-8d16-9f2b9ed8fd3a
protected JRadioButton getWithdrawalRadioButton() { return withdrawalRadioButton; }
9de3444f-7c58-4487-be65-4502d76f108a
public MainFrame() { super(); setSize(750, 300); setLocation(100, 100); setDefaultCloseOperation(EXIT_ON_CLOSE); listPanel = new JPanel(); listPanel.setLayout(new BoxLayout(listPanel, BoxLayout.Y_AXIS)); openButtonFrame(); scrollPane = new JScrollPane(listPanel); add(scrollPane); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Serializer.saveState(); } }); TransactionList list = Serializer.getInstance(); if (list.isEmpty()) { addNewTransaction(); } else { for (Transaction t : list) { this.addNewTransaction(t); } } setVisible(true); System.out.println("this is my code please be a code."); updateBalance(); }
f24e5817-242e-40d3-a7c0-34d6e781828f
@Override public void windowClosing(WindowEvent e) { Serializer.saveState(); }
a3f968b8-2350-47cc-8595-d45172003a0b
public static List<TransactionPanel> getTransactionPanelList() { return listOfTransactionPanels; }
eb9d03aa-f605-4caf-806f-cfe998d0a4ff
public static void main(final String[] args) { MainFrame m = new MainFrame(); m.doNothing(); }
4b2ec311-91c6-4a6d-93ae-1a97c34f6cc7
public JTextField getBalanceField() { return balanceField; }
89df2358-e206-46fb-b480-211357d5dd50
public MainFrame getMainFrame() { return this; }
6d6096ee-f1a0-4ba5-b0e6-96589c7630d5
public void updateBalance() { Money balance = new Money(); for (TransactionPanel tp : getTransactionPanelList()) { Transaction tmp = tp.getTransaction(); if (tmp.isDeposit()) { balance = Money.add(balance, tmp.getMoney()); } else { balance = Money.add(balance, tmp.getMoney().negateTmp()); } } getBalanceField().setText(balance.toString()); }
b36bc995-7c78-48ba-9452-8033c5bd8afa
private void doNothing() { }
7f35e42e-c57f-4957-80f7-e99c3a25cc12
private void openButtonFrame() { JFrame buttonFrame = new JFrame(); buttonFrame.setSize(300, 100); buttonFrame.setLocation(800, 800); buttonFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); addRowButton = new JButton("New Entry"); addRowButton.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { addNewTransaction(); Serializer.saveState(); } }); balanceField = new JTextField(10); balanceField.setText("$0.00"); balanceField.setEnabled(false); saveButton = new JButton("Save"); buttonPanel.add(addRowButton); buttonPanel.add(balanceField); buttonPanel.add(saveButton); buttonFrame.add(buttonPanel); buttonFrame.setVisible(true); }
b59263b1-2a13-4858-a00e-a55be9f73095
@Override public void actionPerformed(final ActionEvent e) { addNewTransaction(); Serializer.saveState(); }
aa3d361f-b17c-42cb-a0fc-29807661efd8
protected void addNewTransaction() { this.addNewTransaction(new Transaction()); }
bc9b6d98-e500-41d0-b7bc-09fb8fb4249a
protected void addNewTransaction(final Transaction t) { TransactionPanel tmp = new TransactionPanel(this, t); // Allocate new listOfTransactionPanels.add(tmp); // Add to ArrayList of Panels listPanel.add(tmp); // Add to JPanel revalidate(); }
879e211b-2f7f-4834-8c9f-f7ad7564607a
protected boolean removeTransactionByID(final int ID) { for (TransactionPanel t : listOfTransactionPanels) { if (t.getTransaction().getID() == ID) { // Check if found listPanel.remove(t); // Remove from Panel listOfTransactionPanels.remove(t); // Remove from list return true; } } revalidate(); return false; }
5009dce4-cd92-46eb-8220-c0e65603a3c6
@Override public void nativeKeyPressed(NativeKeyEvent nativeKeyEvent) { if (nativeKeyEvent.getKeyCode() == NativeKeyEvent.VK_DELETE) { if (uiFlag == 0) { Main.supporting.start(); Main.healing.start(); Main.fighting.start(); uiFlag = 1; System.out.println("\nStarted."); } else if (uiFlag == 1) { uiFlag = 2; Monitor.flag = true; System.out.println("Paused..."); } else { uiFlag = 1; synchronized (Monitor.setState) { Monitor.flag = false; Monitor.setState.notifyAll(); } System.out.println("Running again!"); } } }
990a34af-3437-4092-801d-67406a51e204
@Override public void nativeKeyReleased(NativeKeyEvent nativeKeyEvent) {/*NOP*/}
9c0cf0ee-19f2-42c3-834a-ec39efb5b103
@Override public void nativeKeyTyped(NativeKeyEvent nativeKeyEvent) {/*NOP*/}
4b61aaa4-2ff1-4863-b1f5-9cdbad9b6c84
public static void initializeUI() { System.out.println("Welcome!"); System.out.println("Dou you want to set directions? (y/n)"); decision = keyboard.nextLine(); if (decision.equals("y")) { System.out.println("\nType first direction:"); firstDirection = keyboard.nextLine(); System.out.println("Oh, " + firstDirection + ", fine."); System.out.println("Type the opposite direction:"); secondDirection = keyboard.nextLine(); System.out.println("How many seconds between each to walk?"); steps = keyboard.nextInt(); System.out.println("Go " + firstDirection + " for " + steps + " seconds and then come back to " + secondDirection + ". Got it.\n"); } else if (decision.equals("n")) { System.out.println("You chose not to move. "); } System.out.println("Press DELETE to start the application. \nPress again to pause. \nClose this window to exit.\n"); }