2021-08-05
This commit is contained in:
34
swing/src/main/java/kr/pe/elex/examples/Application.java
Normal file
34
swing/src/main/java/kr/pe/elex/examples/Application.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application implements CommandLineRunner {
|
||||
|
||||
@Autowired
|
||||
private JFrame window;
|
||||
//@Autowired
|
||||
//private MyPanel contentPane;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ConfigurableApplicationContext context
|
||||
= new SpringApplicationBuilder(Application.class)
|
||||
.headless(false)
|
||||
.run(args);
|
||||
//SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(String... arg0) throws Exception {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
window.setVisible(true);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
23
swing/src/main/java/kr/pe/elex/examples/Config.java
Normal file
23
swing/src/main/java/kr/pe/elex/examples/Config.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
@Configuration
|
||||
public class Config {
|
||||
@Autowired
|
||||
private MyPanel contentPane;
|
||||
|
||||
@Bean
|
||||
public JFrame window(){
|
||||
final JFrame jFrame = new JFrame();
|
||||
jFrame.setTitle("Test");
|
||||
jFrame.setSize(800, 600);
|
||||
jFrame.setContentPane(contentPane);
|
||||
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
return jFrame;
|
||||
}
|
||||
}
|
||||
31
swing/src/main/java/kr/pe/elex/examples/MyPanel.java
Normal file
31
swing/src/main/java/kr/pe/elex/examples/MyPanel.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class MyPanel extends JPanel {
|
||||
//@Autowired
|
||||
//private JFrame window;
|
||||
@Autowired
|
||||
private MyService service;
|
||||
|
||||
public MyPanel() {
|
||||
super();
|
||||
|
||||
this.setLayout(new BorderLayout());
|
||||
JButton btn = new JButton("Button");
|
||||
this.add(new JLabel("Hello"), BorderLayout.CENTER);
|
||||
this.add(btn, BorderLayout.SOUTH);
|
||||
|
||||
btn.addActionListener(e -> {
|
||||
//System.out.println(window.getTitle());
|
||||
System.out.println(service.getText());
|
||||
});
|
||||
}
|
||||
}
|
||||
11
swing/src/main/java/kr/pe/elex/examples/MyService.java
Normal file
11
swing/src/main/java/kr/pe/elex/examples/MyService.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package kr.pe.elex.examples;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MyService {
|
||||
public String getText(){
|
||||
return "Hello~";
|
||||
}
|
||||
}
|
||||
3
swing/src/main/resources/application.yaml
Normal file
3
swing/src/main/resources/application.yaml
Normal file
@@ -0,0 +1,3 @@
|
||||
spring:
|
||||
main:
|
||||
web-application-type: none
|
||||
Reference in New Issue
Block a user