Java Programming Tutorial – 83 – FlowLayout

[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –


Posted

in

by

Tags:

Comments

43 responses to “Java Programming Tutorial – 83 – FlowLayout”

  1. Bruh Avatar

    Guys what is the container used for ?

  2. Anurag Avatar

    I have made written notes of all your videos, color coded and also, sidenotes from comments. I learned so much.

  3. Mark Alexa Avatar

    Getting errors on lines 13 and 14. Line 13 says "return type for the method is missing" and line 14 says "constructor call must be the first statement in a constructor". What do I do ?

  4. Saksham Goyal Avatar

    can you acutually post teh full link to the source code? i dont want to find it in the github page….

  5. Paulo Nikko Peral Avatar

    Thanks for these videos man! I really really really appreciate it, you explain it really good. You should be a programming teacher. 🙂

  6. Idiot Productions Avatar

    Could someone explain what the purpose of the container object is? My program worked, but I don't understand what exactly the container did/does in the program.

  7. Charles_IV Avatar

    helpful.
    easy to understand by newbie

  8. AyToNiic Avatar

    IF anyone else is having a problem with there main class, remember that "Layout 1" is actually "Layout l"

    l as in L guys its not the number one…hard to tell with console font xD

  9. Prince Gupta Avatar

    I thought we'll be creating our own layout.

  10. Matias Vega Avatar

    How could you add up and down buttons to make the container move up and down?

  11. Kees Hottinga Avatar

    Without an anonymous class, a handler is required.

    public class Layout extends JFrame
    {
    private JButton lb;
    private JButton cb;
    private JButton rb;
    private FlowLayout layout;
    private Container container;

    public Layout()
    {
    super("Title tutorial 83");
    layout = new FlowLayout();
    container = getContentPane();
    setLayout(layout);

    lb = new JButton("left");
    cb = new JButton("center");
    rb = new JButton("right");
    add(lb);
    add(cb);
    add(rb);

    // Without an anonymous class a 'handler' is required.
    HandlerClass handler = new HandlerClass();
    lb.addActionListener(handler);
    cb.addActionListener(handler);
    rb.addActionListener(handler);
    }

    private class HandlerClass implements ActionListener
    {
    // All methods in 'ActionListener' must be overwritten; N.B. Only 1 method in this class.
    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource() == lb)
    layout.setAlignment(FlowLayout.LEFT);
    else if (e.getSource() == cb)
    layout.setAlignment(FlowLayout.CENTER);
    else if (e.getSource() == rb)
    layout.setAlignment(FlowLayout.RIGHT);
    layout.layoutContainer(container);
    }
    }
    }

  12. fars had Avatar

    im getting an error 'The constructor JButton(string) is undefined' and i cant figure out why, here's my code:

    package lesson1;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class Layout1 extends JFrame {

    private JButton lb;
    private JButton cb;
    private JButton rb;
    private FlowLayout layout;
    private Container container;

    public Layout1 () {
    super ("the title");
    layout = new FlowLayout();
    container = getContentPane();
    setLayout(layout);

    lb = new JButton("left");
    add(lb);
    lb.addActionListener (
    new ActionListener() {
    public void actionPerformed(ActionEvent event) {
    layout.setAlignment(FlowLayout.LEFT);
    layout.layoutContainer(container);
    }
    }
    );
    cb = new JButton("center");
    add(cb);
    cb.addActionListener (
    new ActionListener() {
    public void actionPerformed(ActionEvent event) {
    layout.setAlignment(FlowLayout.CENTER);
    layout.layoutContainer(container);
    }
    }
    );
    rb = new JButton("right");
    add(rb);
    rb.addActionListener (
    new ActionListener() {
    public void actionPerformed(ActionEvent event) {
    layout.setAlignment(FlowLayout.RIGHT);
    layout.layoutContainer(container);
    }
    }
    );
    }
    }

  13. ShisHiR Avatar

    what is the difference between setLayout(new FlowLayout()) and
    layout=new FlowLayout
    ……
    ……
    setLayout(layout)

  14. Shankar HavoC Avatar

    Can anyone tell me what is the use of the Container?

  15. RoyalRo Avatar

    I got an annoying error because "Layout l = new Layout();" with "1" instead of "l" XD

  16. josh hamil Avatar

    What's this container anyway ? Anyone having insight on this..

  17. Somber Response Avatar

    anyone see the error in here?

    import javax.swing.JFrame;

    public class JAY {
    public static void main (String[] args) {

    Layout 1 = new Layout ();
    1.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
    1.setSize (300,100);
    1.setVisible (true);

    }

    }

  18. Risto Bozinov Avatar

    how awesome is that!

  19. Steven Davis Avatar

    If you are getting "Syntax error, insert ";" to complete BlockStatements" when you hover over Layout in your bucky class, then you probably have a number one (1) instead of a lower case L in your Layout declaration. If you have that incorrect, you probably have a number one in the three lines below also (like I did).

  20. DarrenthePopKidz Avatar

    Meanwhile, I'm still using my class apples…

  21. Manoj Khatri Avatar

    What is the difference between Container and JPanel??

  22. tchouta hermann Avatar

    i like your tutorials. really instructing. God bless u. thanks 🙂

  23. khoa nguyen Avatar

    you are awesome bro. I followed your tutorials from beginning and learnt a lot. Thanks

  24. RustinPieber Avatar

    Is it necessary to reset the container?

  25. SgtDrPeppers Avatar

    To stop a user from being able to resize the window and mess all the positions up you can use in your launcher method: "objectname.setResizable(false);"

  26. Epicnerd73 Avatar

    The word 'layout' looks so deformed

  27. Mellumen Avatar

    This is also a way of doing it: http://pastebin.com/gdx5FncU
    Not so much repeating

  28. Noah Snell Avatar

    This will place the top left corner in the center of the screen. To actually center the box, this code should go in your main class, such as:
    l.setSize(300, 100);
    l.setLocationRelativeTo(null);

  29. Key Word, Cacti Avatar

    ahh you basterd! 😀 lol

  30. Alpha Unit Tom Avatar

    I knew most of these, although ctrl+space and ctrl+shift+f are new to me, and will come in handy! Thanks!

  31. Potato Puke Avatar

    And don't forget ALT+F4 before saving your code, it uhm.,.cleans it up!

  32. J.J. L. Avatar

    Nevermind….it took me a couple of beers to see clearly that the "1" is a lower case L "l"

    haha

  33. J.J. L. Avatar

    Hi Bucky-

    When I went through this tutorial, i noticed that you named your instance of Layout using an integer…..

    when I did that, i got errors saying "layout cannot be resolved to an integer"

    I renamed it "one" to get around it…wanted to know why this is the case.

  34. George Petropoulos Avatar

    Summup: Size doesn't matter !

  35. Lawr Leaf Avatar

    I may delete my Gui class. I may even delete my tuna class, but I will NEVER delete my apples class!

  36. I poop Rainbows Avatar

    He likes his code bigger.

  37. Wei Zhang Avatar

    hah. I got it. The getContentPane() is a build in method of JFrame, and it will will return contentpane object. THe container is the collection of all components in it. The reason we need to use container is to give the operate object to the layout.LayoutContainer() method.

  38. Wei Zhang Avatar

    I am going to ask the same question.

  39. Janel Logrono Avatar

    whats the purpose of container

  40. Dhruv Sharma Avatar

    Dude Bucky i was shouting that you forgot to change the names for the buttons, but you did not listen and now you ended up embarrassing yourself!

  41. Filip Gnesin Avatar

    I understand your point, and I somewhat agree! But I just don't think that there's any reason to act the way you did(/do). You could've answered politely, and not make him feel dumb. That's the only part I'm complaining about.

  42. tyraende Avatar

    The atmosphere is whatever you perceive it to be. You want to argue and defend youtube's community this much? Fine with me. You want to learn programming? Do it however you want. You want quick answers from strangers? Ask them on a youtube video (response quality may vary). Just so you can't say I didn't "contribute" to your nice little community, the answer to the original question is "encapsulation". Now, I could suggest reading a book about it, but you know..

Leave a Reply

Your email address will not be published. Required fields are marked *