2021-08-05
This commit is contained in:
@@ -7,4 +7,4 @@
|
|||||||
|
|
||||||
rootProject.name = "spring-boot-examples"
|
rootProject.name = "spring-boot-examples"
|
||||||
include("file-upload", "security", "security-with-jpa", "validation", "testing",
|
include("file-upload", "security", "security-with-jpa", "validation", "testing",
|
||||||
"mqtt", "websocket", "restful")
|
"mqtt", "websocket", "restful", "swing")
|
||||||
|
|||||||
1
swing/README.md
Normal file
1
swing/README.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
# Spring-boot for Swing
|
||||||
26
swing/build.gradle.kts
Normal file
26
swing/build.gradle.kts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-spring-boot")
|
||||||
|
|
||||||
|
id("org.springframework.boot") version "2.5.3"
|
||||||
|
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
//implementation("org.springframework.boot:spring-boot-starter-mustache")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
|
||||||
|
compileOnly("org.projectlombok:lombok")
|
||||||
|
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
|
|
||||||
|
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
|
|
||||||
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
|
}
|
||||||
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