자바 지명 기 인 스 턴 스 구현
8345 단어 자바
package personal;
import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class StartJFrame extends JFrame{
private static final long serialVersionUID = 1L;
JFrame jframe= new JFrame(" ");
JPanel jpanel=null;
JPanel imagePanel = null;
BufferedImage image= null;
JLabel label3 = new JLabel();
ImageIcon background = new ImageIcon();
JTextArea jtext = new JTextArea();
JButton jbutton1=new JButton(" ");
JButton jbutton2=new JButton(" ");
JButton jbutton3=new JButton(" ");
String strPath = "";
public static boolean flag = true;//
private static Thread t;
private int count = 0;
public StartJFrame(){
//
try {
image=ImageIO.read(new File("F:\\ \\95.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
background = new ImageIcon(image);
//
JLabel label = new JLabel(background);
//
label.setBounds(0,0,450,400);
// JPanel, setOpaque()
imagePanel = (JPanel)getContentPane();
imagePanel.setOpaque(false);
//
getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));
//
jpanel = (JPanel)this.getContentPane();//
JLabel label2 = new JLabel(" TXT :");
Font font = new Font("",Font.BOLD,30);
label2.setFont(font);
label2.setForeground(Color.yellow);
label2.setBounds(20,50,450,100);
jpanel.add(label2);
//
jpanel=(JPanel)this.getContentPane();
jpanel.setLayout(null);
//( , , , )
jbutton3.setBounds(new Rectangle(330,180,60,20));
jbutton3.addActionListener(new TextValue(this));
jpanel.add(jbutton3);
// ( , , , )
jtext.setBounds(40, 180, 260, 20);
jpanel.add(jtext);
}
/**
*
*/
public StartJFrame(String str){
//
strPath = str;
//
try {
image=ImageIO.read(new File("F:\\ \\95.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
background = new ImageIcon(image);
//
JLabel label = new JLabel(background);
//
label.setBounds(0,0,450,400);
// JPanel, setOpaque()
imagePanel = (JPanel)getContentPane();
imagePanel.setOpaque(false);
//
getLayeredPane().add(label,new Integer(Integer.MIN_VALUE));
//
jpanel = (JPanel)this.getContentPane();//
JLabel label2 = new JLabel(" !!!");
Font font = new Font("",Font.BOLD,30);
label2.setFont(font);
label2.setForeground(Color.yellow);
label2.setBounds(100,20,450,100);
jpanel.add(label2);
//
label3.setBounds(150,120,450,100);
//
label3.setForeground(Color.yellow);
//
jpanel=(JPanel)this.getContentPane();
jpanel.setLayout(null);
jbutton1.setBounds(new Rectangle(100,300,75,25));
jpanel.add(jbutton1);
jbutton1.addActionListener(new Action(this));
jbutton2.setBounds(new Rectangle(250,300,75,25));
jpanel.add(jbutton2);
jbutton2.addActionListener(new Stop(this));
}
/**
*
*/
public static String InputPath(){
String str ="";
System.out.println(" TXT :");
Scanner sc= new Scanner(System.in);
str = sc.nextLine();
return str;
}
/**
*
* @param filePath
* @return
*/
public static String ReadFile(String filePath){
String str = "";
try {
String encoding="GBK";
File file = new File(filePath);
if(file.isFile()&&file.exists()){
InputStreamReader reader =
new InputStreamReader(new FileInputStream(file),encoding);
BufferedReader bufferedReader = new BufferedReader(reader);
String lineTxt = "";
while((lineTxt = bufferedReader.readLine()) != null){
str+=lineTxt+";
";
}
reader.close();
}else{
System.out.println(" ");
}
}catch (Exception e) {
System.out.println(" ");
e.printStackTrace();
}
return str;
}
/**
* String
*/
public static String[] ChangeType(String str){
ArrayList list=new ArrayList();
String[] string = str.split(";");
return string;
}
/**
* main
* @param args
*/
public static void main(String args[]){
StartJFrame jframe=new StartJFrame();
jframe.setTitle(" ");
jframe.setSize(450,400);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setResizable(false);
jframe.setLocationRelativeTo(null);
System.out.println();
}
/**
*
*/
public void chooseValue(ActionEvent e){
String str = "";
str = jtext.getText();
if(str != "" || str != null){
StartJFrame jframe = new StartJFrame(str);
jframe.setTitle(" ");
jframe.setSize(450,400);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setResizable(false);
jframe.setLocationRelativeTo(null);
System.out.println(str);
}
}
/**
*
*/
public void actionRun(ActionEvent e){
if(flag){
//
t = new Thread(new Runnable(){
public void run(){//
while(count<=10000){
//
String strTest = strPath;
//
String strRead = ReadFile(strTest);
//
String[] strc = ChangeType(strRead);
//
Random random = new Random();
int a = 0;
a = random.nextInt(strc.length-1);
String str = strc[a];
System.out.println(" :"+str);
label3.setFont(new java.awt.Font(str,1,60));
//
label3.setText(str);
try{
t.sleep(20);// 50
}catch(Exception e){
e.printStackTrace();
}
count+=1;//
}
}
});
t.start();
//
jpanel.add(label3);
flag = false;
}
flag = false;
}
/**
*
*/
public void stopRun(ActionEvent e){
if(!flag){
t.stop();
flag = true;
}
flag = true;
}
}
/**
*
*/
class TextValue implements ActionListener {
private StartJFrame startJFrame;
TextValue(StartJFrame startJFrame) {
this.startJFrame = startJFrame;
}
public void actionPerformed(ActionEvent e) {
startJFrame.chooseValue(e);
startJFrame.setVisible(false);
}
}
/**
*
*/
class Action implements ActionListener {
private StartJFrame jFrameIng;
Action(StartJFrame jFrameIng) {
this.jFrameIng = jFrameIng;
}
public void actionPerformed(ActionEvent e) {
jFrameIng.actionRun(e);
}
}
/**
*
*/
class Stop implements ActionListener {
private StartJFrame jFrameIng;
Stop(StartJFrame jFrameIng) {
this.jFrameIng = jFrameIng;
}
public void actionPerformed(ActionEvent e) {
jFrameIng.stopRun(e);
}
}
이름 목록 경 로 를 입력 하려 면 txt 형식 문 서 를 사용 하고 이름 을 세로 로 배열 하면 됩 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.