[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Java Programming Tutorial – 83 – FlowLayout
by
Tags:
Comments
43 responses to “Java Programming Tutorial – 83 – FlowLayout”
-
Guys what is the container used for ?
-
I have made written notes of all your videos, color coded and also, sidenotes from comments. I learned so much.
-
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 ?
-
can you acutually post teh full link to the source code? i dont want to find it in the github page….
-
Thanks for these videos man! I really really really appreciate it, you explain it really good. You should be a programming teacher. 🙂
-
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.
-
helpful.
easy to understand by newbie -
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
-
I thought we'll be creating our own layout.
-
How could you add up and down buttons to make the container move up and down?
-
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);
}
}
} -
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);
}
}
);
}
} -
what is the difference between setLayout(new FlowLayout()) and
layout=new FlowLayout
……
……
setLayout(layout) -
Can anyone tell me what is the use of the Container?
-
I got an annoying error because "Layout l = new Layout();" with "1" instead of "l" XD
-
What's this container anyway ? Anyone having insight on this..
-
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);}
}
-
how awesome is that!
-
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).
-
Meanwhile, I'm still using my class apples…
-
What is the difference between Container and JPanel??
-
i like your tutorials. really instructing. God bless u. thanks 🙂
-
you are awesome bro. I followed your tutorials from beginning and learnt a lot. Thanks
-
Is it necessary to reset the container?
-
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);"
-
The word 'layout' looks so deformed
-
This is also a way of doing it: http://pastebin.com/gdx5FncU
Not so much repeating -
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); -
ahh you basterd! 😀 lol
-
I knew most of these, although ctrl+space and ctrl+shift+f are new to me, and will come in handy! Thanks!
-
And don't forget ALT+F4 before saving your code, it uhm.,.cleans it up!
-
Nevermind….it took me a couple of beers to see clearly that the "1" is a lower case L "l"
haha
-
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.
-
Summup: Size doesn't matter !
-
I may delete my Gui class. I may even delete my tuna class, but I will NEVER delete my apples class!
-
He likes his code bigger.
-
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.
-
I am going to ask the same question.
-
whats the purpose of container
-
6 did bro
-
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!
-
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.
-
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