d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help With Mousedrag > Yup
Add Reply New Topic New Poll
Member
Posts: 3,958
Joined: Apr 24 2013
Gold: 0.00
Sep 25 2016 11:13am
I'm trying to sum up 2 buttons to give a total.

When i drag 1 buttons onto another, both buttons add up to give a total. Help
Member
Posts: 3,958
Joined: Apr 24 2013
Gold: 0.00
Sep 25 2016 11:19am
This is how i Add up my buttons, and I've added them into an ArrayList, but I have a hard time reaching a button in the Array list.

for(int i = 0; i < tabChar.length; i++){

JButton btnNewButton = new JButton(String.valueOf(tabChar));
buttons.add(i,btnNewButton);
btnNewButton.setFont(new Font("Arial", Font.PLAIN, 40));
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
gbc_btnNewButton.insets = new Insets(0, 1, 70, 6);
gbc_btnNewButton.gridx = i;
gbc_btnNewButton.gridy = 0;
gbc_btnNewButton.weightx = 1;
btnNewButton.setPreferredSize(dimension);
btnNewButton.setOpaque(true);
btnNewButton.setBackground(Color.WHITE);
frame.getContentPane().add(btnNewButton, gbc_btnNewButton);
btnNewButton.addMouseListener(new MouseListener() {

Here is where i Would want the mouse drag. For each button, if i use mouse drag and drag it onto another button, they sum up
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Sep 25 2016 05:50pm
Quote
I have a hard time reaching a button in the Array list.


what do you mean by this? you're not sure how to access the elements? your arraylist is not in scope?

Quote
btnNewButton.addMouseListener(new MouseListener() {
Here is where i Would want the mouse drag. For each button, if i use mouse drag and drag it onto another button, they sum up


i dont have any experience with java drag+drop. a quick google search has an example that should give you a starting point:
http://stackoverflow.com/questions/28844574/drag-and-drop-from-jbutton-to-jcomponent-in-java



instead of replacing the text, have it add.
Member
Posts: 3,958
Joined: Apr 24 2013
Gold: 0.00
Sep 25 2016 07:15pm
I had help from my cousin, its settled, thanks though :)
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll