2021-08-05

This commit is contained in:
2021-08-05 18:55:32 +09:00
parent 0f4d342354
commit c1083a6884
9 changed files with 130 additions and 1 deletions

1
swing/README.md Normal file
View File

@@ -0,0 +1 @@
# Spring-boot for Swing

26
swing/build.gradle.kts Normal file
View 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")
}

View 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);
});
}
}

View 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;
}
}

View 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());
});
}
}

View 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~";
}
}

View File

@@ -0,0 +1,3 @@
spring:
main:
web-application-type: none