feoleb's Profile
Reputation: -1
Dishonored
- Group:
- Members
- Active Posts:
- 46 (0.22 per day)
- Joined:
- 24-November 12
- Profile Views:
- 479
- Last Active:
Mar 28 2013 12:48 PM- Currently:
- Offline
Previous Fields
- Country:
- US
- OS Preference:
- Windows
- Favorite Browser:
- Chrome
- Favorite Processor:
- AMD
- Favorite Gaming Platform:
- PC
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: JButton array to shorten program
Posted 22 Mar 2013
jon.kiparsky, on 21 March 2013 - 01:40 PM, said:Sorry, you need a new operator in there.
private JButton button_array [] = new JButton[12];
Please keep in mind that I'm typing this stuff up while I'm at my day job. Try to help me out a bit here, and apply a little DWIM logic - you know how to do an array initialization, right? You can see that's what I'm asking you to do, right? Okay, so try that. Oh, look, it works.
No, I can't see what you were trying to do. That's why I asked my question. If you are unable to answer, or you do not have time to answer, then you are not required to. This is a forum. You are not my employee, you are not my coworker, my boss, or my personal teacher. I understand that your own life comes first, and it should. If I ask a question, it is because I tried to understand, and I failed to. With programming, especially when learning, one bracket, one quotation, can mean a hundred different things. You know some of what is possible, so you have a better understanding of where a program is trying to go. I don't know what is possible, so my view of where people are trying to go with a program can be like trying to find a needle in a haystack. I usually assume that when people give me code, that it's correct, so I must have done something wrong. Usually I'm right. Some people here have expressed frustration with my inability to understand these concepts. That frustration is do to the energy and time it takes to get me from where I am, to where I need to be. If you don't have the energy or the time, you are not a bad person, and I don't take it personally. You are not required to respond in a specific time frame, or with a specific amount of detail. -
In Topic: JButton array to shorten program
Posted 21 Mar 2013
jon.kiparsky, on 21 March 2013 - 12:59 PM, said:
feoleb, on 21 March 2013 - 02:50 PM, said:I want to create a shorter program. When I started, I manually created each button. So, rather than do that, I'd just like to have a for loop.
Right, exactly. So why do you want to create 12 variables to point to these buttons? A JButton array is all you need.
private JButton button_array [] = JButton[12]; for (int i = 0; i < button_array.length; i+) { button_array[i] = new JButton(); // other initialization stuff here }
And then you're done.
If I try to replace
private JButton button_array [] = {jone, jtwo, jthree, jfour, jfive, jsix, jseven, jeight,
jnine, jten, jtest, jclear};
with
private JButton button_array [] = JButton[12];
it says that JButton can't be resolved to a variable. -
In Topic: JButton array to shorten program
Posted 21 Mar 2013
I want to create a shorter program. When I started, I manually created each button. So, rather than do that, I'd just like to have a for loop. -
In Topic: JButton array to shorten program
Posted 21 Mar 2013
Why can't I do the for loop like this?
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Arrays; public class ElevatorPanel extends JFrame implements ActionListener { public ElevatorPanel() { initialize(); } public static void main(String[] args) { ElevatorPanel thisFrame = new ElevatorPanel(); thisFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); thisFrame.setSize(200,600); thisFrame.setVisible(true); } @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub } //declare JButton type buttons private JButton jone; private JButton jtwo; private JButton jthree; private JButton jfour; private JButton jfive; private JButton jsix; private JButton jseven; private JButton jeight; private JButton jnine; private JButton jten; private JButton jtest; private JButton jclear; private JButton button_array [] = {jone, jtwo, jthree, jfour, jfive, jsix, jseven, jeight, jnine, jten, jtest, jclear}; private String buttonTxt [] = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10" , "test", "clear" }; private void initialize() { String buttoncaption = null; for (int i = 0; i < 12; i++) { button_array[i] = new JButton(buttonTxt); } -
In Topic: JButton array to shorten program
Posted 20 Mar 2013
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
Contact Information
- E-mail:
- Private
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
feoleb has no profile comments yet. Why not say hello?