Results 1 to 2 of 2
  1. #1
    OPTYMISTA is offline Member
    Join Date
    Feb 2013
    Posts
    18
    Rep Power
    0

    Default Calendar using JComboBox and Arrays

    Hi again! ;)

    This time I want to create a calendar in GUI, using JComboBoxes and Arrays.

    Java Code:
    JComboBox<String> maned, n_dag;
    String[] manedStrings = { "Januar", "Februar", "Mars", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Desember"};
    	int[] dag31 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
    	int[] dag30 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30};
    	int[] dag29 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29};
    	int[] dag28 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28};
    	ArrayList<String> valg = new ArrayList<>();
    
    		maned = new JComboBox<String>(manedStrings);
    			maned.setSelectedIndex(0);
    			maned.setEditable(true);
    			manedLytter manedLytt = new manedLytter();
    			maned.addActionListener(manedLytt);
    
    			System.out.println(Arrays.toString(dag31));
    			valg.equals(Arrays.toString(dag31));
    			System.out.print(valg);
    			n_dag = new JComboBox();
    			//n_dag.setSelectedIndex(0);
    			n_dag.setEditable(true);
    and manedLytter
    Java Code:
    public void actionPerformed(ActionEvent e) {
    			if(maned.getSelectedItem().equals("Januar") || maned.getSelectedItem().equals("Mars")) {
    			valg.equals(dag31);
    			}
    			if(maned.getSelectedItem().equals("Mai") || maned.getSelectedItem().equals("Juli")) {
    				valg.equals(Arrays.toString(dag31));
    			}
    			if(maned.getSelectedItem().equals("August") || maned.getSelectedItem().equals("Oktober")) {
    				valg.equals(Arrays.toString(dag31));
    			}
    			if(maned.getSelectedItem().equals("Desember")){
    				valg.equals(Arrays.toString(dag31));
    			}
    			if(maned.getSelectedItem().equals("Februar")){
    			valg.equals(Arrays.toString(dag28));
    			}
    			else {
    				valg.equals(Arrays.toString(dag30));
    			}
    		}
    By this code, I mean that if user choose month "February", program limits days in ComboBox to 28. For some reason when I test this code:
    Java Code:
    valg.equals(Arrays.toString(dag31));
    I get printed out, some weird code:
    Java Code:
    [Ljava.lang.String;@33d87ab8
    . I think that's the reason why I get an error message. I'd be grateful if You could help me understand this issue. Or it that any else or easier way to do it. I'll try
    Java Code:
     java.util.Calendar;
    java.util.GregorianCalendar;
    Last edited by OPTYMISTA; 04-02-2013 at 02:08 PM.

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Calendar using JComboBox and Arrays

    Your equals() method is not printing anything out as you've said, it's this line that's printing something out:

    System.out.print(valg);

    And since valg is an ArrayList, it doesn't really know what to output, so it outputs that gobbledygook. In other words, the toString() method of ArrayList returns a String that looks like what you're seeing.

    If you want something else to print out, you'll have to change your code.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. Calendar now = Calendar.getInstance()
    By volkvanmyn25 in forum New To Java
    Replies: 3
    Last Post: 10-31-2011, 11:25 PM
  2. Replies: 4
    Last Post: 09-21-2011, 05:39 PM
  3. Replies: 9
    Last Post: 04-08-2010, 02:37 PM
  4. Arrays.sort... why sorting all arrays in class?
    By innspiron in forum New To Java
    Replies: 6
    Last Post: 03-23-2010, 02:40 AM
  5. Replies: 2
    Last Post: 12-10-2009, 02:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •