2021-08-07
This commit is contained in:
@@ -4,6 +4,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@@ -13,17 +14,20 @@ public class MyPanel extends JPanel {
|
||||
|
||||
@Autowired
|
||||
private MyService service;
|
||||
@Autowired
|
||||
private MyToolbar toolbar;
|
||||
|
||||
public MyPanel() {
|
||||
super();
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
this.setLayout(new BorderLayout());
|
||||
JButton btn = new JButton("Button");
|
||||
this.add(new JLabel("Hello"), BorderLayout.CENTER);
|
||||
this.add(btn, BorderLayout.SOUTH);
|
||||
this.add(toolbar, BorderLayout.NORTH);
|
||||
|
||||
btn.addActionListener(e -> {
|
||||
System.out.println(service.getText());
|
||||
System.out.println(service.getSomething());
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,16 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MyService {
|
||||
public String getText(){
|
||||
@Getter @Setter
|
||||
private String something = "Something";
|
||||
|
||||
public String getText() {
|
||||
return "Hello~";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
22
swing/src/main/java/kr/pe/elex/examples/MyToolbar.java
Normal file
22
swing/src/main/java/kr/pe/elex/examples/MyToolbar.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.swing.*;
|
||||
|
||||
@Component
|
||||
public class MyToolbar extends JToolBar {
|
||||
@Autowired
|
||||
private MyService service;
|
||||
|
||||
@PostConstruct
|
||||
private void init(){
|
||||
|
||||
this.add(new JLabel(service.getSomething()));
|
||||
|
||||
service.setSomething("changed by Toolbar");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user