WinkyCode's Profile User Rating: -----

Reputation: 10 Tradesman
Group:
Members w/DIC++
Active Posts:
165 (0.09 per day)
Joined:
23-February 11
Profile Views:
4,863
Last Active:
User is offline Mar 25 2016 01:57 AM
Currently:
Offline

Previous Fields

Country:
SE
OS Preference:
Linux
Favorite Browser:
Chrome
Favorite Processor:
Intel
Favorite Gaming Platform:
PC
Your Car:
Volkswagen
Dream Kudos:
0

Latest Visitors

Icon   WinkyCode thinking about status...

Posts I've Made

  1. In Topic: Error from code from an course book in Java

    Posted 25 Mar 2016

    Hello!

    The working code after some reading and much appreciated help from xclite and xiledcore, here is the working code.

    import java.awt.*;
    import javax.swing.*;
    
        public class Halsning {
        	public static void main(String[] arg) { //Har borjar det
        		Direkt2 d2 = new Direkt2(); //skapa ett Direkt2-objekt
        	}
        }
        class Direkt2 extends JFrame {
        	public Direkt2() { //Konstruktor, anropas automatiskt
        		JLabel l = new JLabel ("Valkommen till Java Direkt", JLabel.CENTER);
        		add(l); //Placera 1 i fonstret
        		l.setOpaque(true); //ogenomskinlig bakgrund
        		l.setBackground(Color.yellow);
        		l.setForeground(Color.blue);
        		l.setFont(new Font("SansSerif", Font.BOLD, 24));
        		setSize(400,150); //fonstrets storlek
        		setVisible(true); //gor fonstret synligt
        		setDefaultCloseOperation(EXIT_ON_CLOSE);
        	}
        }
    
    


    The mistake I or the author did was:
    • It should a letter not a number. As this is the first chapter of the book, I wish that the author would have used a different letter then the letter "l".
    • It should be "JLabel l = new JLabel..." not as first "JLabel l = (...)"
    • the operator "setSize", "setVisible" and "setDefaultCloseOperation" should not have any dot operator in front.
  2. In Topic: Error from code from an course book in Java

    Posted 25 Mar 2016

    View Postxiledcore, on 24 March 2016 - 08:12 PM, said:

    View PostWinkyCode, on 24 March 2016 - 06:28 PM, said:

    Also, I do not understand why the author use "." instead of "=" when declaring different values for the JLabel.
    This problem occur in the first chapter which makes me worries for the rest. Anyhow, any thoughts?


    Unlike primitive data types such as ints, bytes, shorts (etc), JLabel is an object and you need to refer to its methods in order to give it values. To call the methods, you use the dot operator.

    Now, the JLabel does not contain any methods such as setDefaultCloseOperation. In this case, the JLabel might have been mixed with the JFrame class which represents the whole window.

    As xclite pointed out above, your syntax was also a bit wrong. You cannot give variables or references a name that starts with a number. If you absolutely must, write the number in letters instead. 1 = one. Of course, you should always give your variables or instances of other classes meaningful names.


    Thank you xiledcore for responding :)

    Ah, interesting. This is the second programming course I have and in the first one it was all about the command line. Very dark place. Until I figured out how to change the background in CMD to white and the text to black (yeah, that was a joke). I know now what I will have to search for to learn more about it. Thank you.

    Yeah, I agree. It got me confused why the author wanted numbers. Sitting in front of CMD, I realized that the number "1" is awful similar to the letter "l". Changed it and it is working.
  3. In Topic: Error from code from an course book in Java

    Posted 25 Mar 2016

    View Postxclite, on 24 March 2016 - 07:31 PM, said:

    Ok, two things. One, use "l" (the letter) instead of 1 for the variable name.
    Two, you need to do JLabel l = new JLabel("Valkommen till Java Direkt", JLabel.CENTER);


    Thank you xclite for responding. :)/>

    Yeah, I realized that in monospace the number "1" and the letter "l" look very similar. It is changed now.

    Yeah, I was wondering why it was not so. It is also changed now.
  4. In Topic: Problem with a Java class diagram

    Posted 17 Jan 2016

    View Postmodi123_1, on 17 January 2016 - 07:40 PM, said:

    I would reexamine the arrow.

    https://msdn.microso...=vs.100%29.aspx
    https://msdn.microso...8VS.100%29.aspx
    http://www.cs.sjsu.e...UMLDiagrams.htm
    http://www.ibm.com/d...dge/sep04/bell/

    Also I would figure the 'Dog' class would show all of the important variables, properties, methods, etc.


    Thank you modi123. :) Those link is being bookmarked for reference.

    I talked to a classmate and she explained that I was looking in the wrong way. It is not the DogRegister.java I shall do a class diagram on, it is the Dog.java I shall. So I have send the new version to the teacher. Fingers crossed, I will pass.

    As I understand it, here is the answer to my question about the correct class diagram. It is for the Dog.java program. A classmate kindly pointed out that I was looking in the wrong direction. I shall mark this post as solved. Thanks to modi123_1 for the intressant reading links. :flowers:/>
    Attached File  habi3141.jpg (30.72K)
    Number of downloads: 2
  5. In Topic: I don't understand a programming project question in my course boo

    Posted 28 Dec 2015

    I have done a complete house with ASCII. Here is the code:
    public class PP16 {
    /* Programming project 1.6
     * Write a program that prints the outline
     * of a house using (~) characters
     * 
     */
    
    	public static void main(String[] args) {
    
    System.out.println("     oo");
    System.out.println("     o");
    System.out.println("    ___");
    System.out.println("    | |");
    System.out.println("   ~| |~~~~~~");
    System.out.println("  ~~~~~~~~~~~~");
    System.out.println(" ~~~~~~~~~~~~~~");
    System.out.println("~~~~~~~~~~~~~~~~");
    System.out.println("|    ___   ___ |");
    System.out.println("|   |   |  |+| |");
    System.out.println("|   |o  |  |_| |");
    System.out.println("|___|___|______|");
    	}
    
    }
    
    
    

Friends

WinkyCode hasn't added any friends yet.

Comments

WinkyCode has no profile comments yet. Why not say hello?