Hello need halp on error.

0 Matic Kržičnik · February 16, 2015
I have error on setLayout and on ActionListener plz halp.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Layout extends JFrame{
private JButton lb;
private JButton cb;
private JButton rb;
private FlowLayout layout;
private Container container;

public Layout(){
super("TItel");
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("rigth");
add(rb);
rb.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent event){
layout.setAlignment(FlowLayout.RIGHT);
layout.layoutContainer(container);
}
}
);
}
}


Post a Reply

Replies

Oldest  Newest  Rating
0 Lucas Skarpness · February 17, 2015
I see a couple errors but they are hard to explain. It may just be the size of the code box but yes, there are a few errors.
(Including grammatical errors).
0 Developer John · February 17, 2015
Okay, so there are no errors, but may you tell me what you are trying to do? A checked script of your code that has been looked over for grammar reasons:


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Layout extends JFrame{
private JButton lb;
private JButton cb;
private JButton rb;
private FlowLayout layout;
private Container container;

public Layout(){
super("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);
}
}
);
}
}
  • 1

Java / Android Development

106,938 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator