Skip to content

Commit

Permalink
2016.9.5
Browse files Browse the repository at this point in the history
example and my own codes
  • Loading branch information
FrankisFine authored and FrankisFine committed Sep 6, 2016
1 parent 0e586ac commit cd90236
Show file tree
Hide file tree
Showing 32 changed files with 694 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Logger/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
<classpathentry kind="lib" path="C:/Program Files/JLayer1.0.1/jl1.0.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions Logger/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Logger</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
12 changes: 12 additions & 0 deletions Logger/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7
Binary file added Logger/bin/Logger/Logger.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/CanvesTest.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/FirstSwingExample.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/ImageButton.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/MusicPlayTest.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/Notepad.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/OpenMenu.class
Binary file not shown.
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/Radio.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/RadioExample.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/TextAreaTest.class
Binary file not shown.
Binary file added Logger/bin/SwingStudyExample/WatchTest.class
Binary file not shown.
Binary file added Logger/music.mp3
Binary file not shown.
119 changes: 119 additions & 0 deletions Logger/src/Logger/Logger.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package Logger;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import java.io.File;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;

public class Logger {
private String music;
private int INTERVAL_LENGTH;
private File logTodayPath;

private JFrame settingUpWindow;
private JTextArea dailyGoalTextArea;
private JButton saveAndStartButton;
private JButton openSong;
private JLabel songName;
private JTextField howLongTheIntervalWillbe;
private JLabel intervalLength;
private JPanel leftPanel;
private int screenHeight;
private int screenWidth;

Logger() {
buildAndArrangePanel();
}

private void buildAndArrangePanel() {
setupFrame();
setupLeftPanel();
setupSaveAndStartButton();
setupDailyGoalArea();

settingUpWindow.add(saveAndStartButton, BorderLayout.SOUTH);
settingUpWindow.add(leftPanel, BorderLayout.WEST);
settingUpWindow.add(dailyGoalTextArea, BorderLayout.EAST);

//set all components as visible.
leftPanel.setVisible(true);
dailyGoalTextArea.setVisible(true);
saveAndStartButton.setVisible(true);
settingUpWindow.setVisible(true);
}

private void setupDailyGoalArea() {
dailyGoalTextArea = new JTextArea(25, 23);
dailyGoalTextArea.setText("Today's goal\n");
dailyGoalTextArea.setFont(new Font("Courier", Font.BOLD,50));
dailyGoalTextArea.setBackground(Color.decode("#006699"));
dailyGoalTextArea.setForeground(Color.white);
}

private void setupSaveAndStartButton() {
saveAndStartButton = new JButton("OK Let's start working!");
saveAndStartButton.setFont(new Font("Courier", Font.BOLD,30));
saveAndStartButton.setLayout(null);
}

private void setupLeftPanel() {
leftPanel = new JPanel(new GridBagLayout());

intervalLength = new JLabel("Take a break by following minutes time interval");
intervalLength.setFont(new Font("Courier", Font.BOLD,30));
intervalLength.setLayout(null);
leftPanel.add(intervalLength);

howLongTheIntervalWillbe = new JTextField(5);
howLongTheIntervalWillbe.setLayout(null);
howLongTheIntervalWillbe.setHorizontalAlignment(JTextField.CENTER);
howLongTheIntervalWillbe.setFont(new Font("Courier", Font.BOLD,30));
leftPanel.add(howLongTheIntervalWillbe);

songName = new JLabel("Click Open Music File Button to Chose a Song");
songName.setFont(new Font("Courier", Font.BOLD,30));
songName.setLayout(null);
leftPanel.add(songName);

openSong = new JButton("Open Music File");
openSong.setFont(new Font("Courier", Font.BOLD,30));
openSong.setLayout(null);
leftPanel.add(openSong);

leftPanel.setAlignmentX(java.awt.Component.CENTER_ALIGNMENT);
leftPanel.setLayout (new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
}

private void setupFrame() {
// add the main frame and set up the configurations like size and
// location
settingUpWindow = new JFrame();
// make the window as half of the screen size
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
screenHeight = screen.height / 2;
screenWidth = screen.width / 2;
settingUpWindow.setSize(new Dimension(screenWidth, screenHeight));
// make the window in the center of the screen
settingUpWindow.setLocationRelativeTo(null);
}

private void setUpSaveButtom() {

}

public static void main(String[] args) {
Logger l = new Logger();
}
}
33 changes: 33 additions & 0 deletions Logger/src/SwingStudyExample/CanvesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package SwingStudyExample;

import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JFrame;

public class CanvesTest extends Canvas {

public void paint(Graphics g) {

Toolkit t = Toolkit.getDefaultToolkit();
Image i = null;
try {
i = t.getImage(new URL("http://www.javatpoint.com/images/swingimage.jpg"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
g.drawImage(i, 120, 100, this);

}

public static void main(String[] args) {
CanvesTest m = new CanvesTest();
JFrame f = new JFrame();
f.add(m);
f.setSize(400, 400);
f.setVisible(true);
}

}
19 changes: 19 additions & 0 deletions Logger/src/SwingStudyExample/FirstSwingExample.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package SwingStudyExample;

import javax.swing.JButton;
import javax.swing.JFrame;

public class FirstSwingExample {
public static void main(String[] args) {
JFrame f = new JFrame();// creating instance of JFrame

JButton b = new JButton("click");// creating instance of JButton
b.setBounds(130, 100, 100, 40);// x axis, y axis, width, height

f.add(b);// adding button in JFrame

f.setSize(400, 500);// 400 width and 500 height
f.setLayout(null);// using no layout managers
f.setVisible(true);// making the frame visible
}
}
26 changes: 26 additions & 0 deletions Logger/src/SwingStudyExample/ImageButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package SwingStudyExample;

import java.awt.event.*;
import javax.swing.*;

public class ImageButton {
ImageButton() {
JFrame f = new JFrame();

JButton b = new JButton(new ImageIcon("b.jpg"));
b.setBounds(130, 100, 100, 40);

f.add(b);

f.setSize(300, 400);
f.setLayout(null);
f.setVisible(true);

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {
new ImageButton();
}
}
27 changes: 27 additions & 0 deletions Logger/src/SwingStudyExample/MusicPlayTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package SwingStudyExample;

import java.io.*;
import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.*;

class MusicPlayTest {
public static void main(String args[]){
try{
File file = new File("A:\\Music\\周杰伦\\魔杰座\\02 - 给我一首歌的时间.mp3");
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis);

try{
Player player = new Player(bis);
player.play();
if(player.isComplete()){
player.close();
}
}catch(JavaLayerException e){
e.printStackTrace();
}
}catch(IOException e){
e.printStackTrace();
}
}
}
73 changes: 73 additions & 0 deletions Logger/src/SwingStudyExample/Notepad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package SwingStudyExample;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JTextArea;

class Notepad implements ActionListener {
JFrame f;
JMenuBar mb;
JMenu file, edit, help;
JMenuItem cut, copy, paste, selectAll;
JTextArea ta;

Notepad() {
f = new JFrame();

cut = new JMenuItem("cut");
copy = new JMenuItem("copy");
paste = new JMenuItem("paste");
selectAll = new JMenuItem("selectAll");

cut.addActionListener(this);
copy.addActionListener(this);
paste.addActionListener(this);
selectAll.addActionListener(this);

mb = new JMenuBar();
mb.setBounds(5, 5, 400, 40);

file = new JMenu("File");
edit = new JMenu("Edit");
help = new JMenu("Help");

edit.add(cut);
edit.add(copy);
edit.add(paste);
edit.add(selectAll);

mb.add(file);
mb.add(edit);
mb.add(help);

ta = new JTextArea();
ta.setBounds(5, 30, 460, 460);

f.add(mb);
f.add(ta);

f.setLayout(null);
f.setSize(500, 500);
f.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == cut)
ta.cut();
if (e.getSource() == paste)
ta.paste();
if (e.getSource() == copy)
ta.copy();
if (e.getSource() == selectAll)
ta.selectAll();
}

public static void main(String[] args) {
new Notepad();
}
}
Loading

0 comments on commit cd90236

Please sign in to comment.