public class OOP {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(400, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setLayout(new GridBagLayout());
JTextField textf = new JTextField();
JTextField textf2 = new JTextField();
JButton Mybutton = new JButton("Start");
frame.add(textf, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(2, 2, 2, 2), 0, 0));
frame.add(textf2, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(2, 2, 2, 2), 0, 0));
frame.add(Mybutton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.9,
GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
new Insets(1, 2, 2, 2), 0, 0));
Mybutton.addActionListener(new ButtonActionListener()); // Ошибка
frame.setVisible(true);
frame.pack();
}
}
class ButtonActionListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "Messege box");
}
}
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Party extends Application {
@Override
public void start(Stage primaryStage) {
Button btn = new Button();
btn.setText("Say 'Hello World'");
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("Hello World!");
}
});
StackPane root = new StackPane();
root.getChildren().add(btn);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
$user = (new FacebookRequest($this->session, 'GET', '/me'))->execute()->getGraphObject();
<?php
class String
{
private $str;
function __construct()
{
$this->str = "";
}
function addA()
{
$this->str .= "a";
return $this; // Данная строчка возвращает объект типа String
}
function addB()
{
$this->str .= "b";
return $this; // Данная строчка возвращает объект типа String
}
function printString()
{
echo $this->str;
}
}
$a = new String();
$a->addA()->addB()->printString();
ab