Share Code Quickly

What is Harigami?

Harigami is a simple source code sharing service. You can share source code by an URL which is issued after submission.
You can also run your source code online such as Python, Ruby, JavaScript and so on.
For free.Use for code review.
Preferences

anonymous No title
PHP
<?php
$pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
$pdo->query('CREATE TABLE IF NOT EXISTS kadai3_1_users (
    id INT(5) AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20),
    password VARCHAR(20)
    )');

if(isset($_POST['name']) && isset($_POST['password'])){
    if(strlen($_POST['name']) && strlen($_POST['password'])){
        $name = $_POST['name'];
        $password = $_POST['password'];
        $stmt = $pdo->prepare('INSERT INTO kadai3_1_users (name, password) VALUES (:name, :password)');
        $flag = $stmt->execute(array(':name' => $name, ':password' => $password));
        $user_id = $pdo->lastinsertid();
        if ($flag){
            print('ユーザー登録が完了しました<br>');
            echo 'あなたのユーザー情報<br/>';
            echo "ID: ".$user_id;
            echo "<br/>";
            echo "名前: ".$name;
            echo "<br/>";
            echo "パスワード: ".$password;
            echo "<br/>";
            echo "<br/>";
        }else{
            print('ユーザー登録に失敗しました<br>');
        }
    }else{
        echo '未入力の項目があります<br/>';
    }
}

echo "ユーザー一覧<br/>";
$result_rows = $pdo->query('SELECT * FROM kadai3_1_users');
foreach ( $result_rows as $row ) {
    echo "{$row['id']}";
    echo " {$row['name']}";
    echo "<br/>";
}
echo "<br/>";

?>

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>新規登録フォーム</h1>
    <form action="kadai3_1_signup.php" method="post">
    <p>名前</p>
    <input type = "text" name ="name"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信"><br/>
    </form>
    <a href="http://co-19-271.99sv-coco.com/kadai3_1_top.php">投稿ページ</a>
</body>
</html>
anonymous No title
PHP
<?php
$pdo = new PDO('mysql:host=localhost;dbname=co_19_271_99sv_coco_com', 'co-19-271.99sv-c', 'Xc5tnWDA');
$pdo->query('CREATE TABLE IF NOT EXISTS post_table_apply (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(20),
    comment TEXT,
    date DATE,
    password VARCHAR(20)
    )');

if(isset($_POST['edit']) && isset($_POST['password'])){
    if(strlen($_POST['edit']) && strlen($_POST['password'])){
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $_POST['edit']));
        $edit_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($edit_post['password'] == $password){
            $edit_id = $_POST['edit'];
            $edit_name = $edit_post['name'];
            $edit_txt = $edit_post['comment'];
        }else{
            echo "編集パスワードが間違っています<br/>";
        }
    }else{
        echo "編集番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['delete']) && isset($_POST['password'])){
    if(strlen($_POST['delete']) && strlen($_POST['password'])){
        $delete_id = $_POST['delete'];
        $password = $_POST['password'];
        $stmt = $pdo->prepare('SELECT * FROM post_table_apply WHERE id = :id');
        $stmt->execute(array(':id' => $delete_id));
        $delete_post = $stmt->fetch(PDO::FETCH_ASSOC);
        if($delete_post['password'] == $password){
            $stmt = $pdo->prepare('DELETE FROM post_table_apply WHERE id=:id');
            $stmt->execute(array(':id' => $delete_id));
            echo $delete_id."番の投稿を削除しました<br/>";
        }else{
            echo "削除パスワードが間違っています<br/>";
        }
    }else{
        echo "削除番号かパスワードが空欄になっています<br/>";
    }
}

if(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['password'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['password'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $password = $_POST['password'];
        $date = date("Y-m-d");
        $stmt = $pdo->prepare('INSERT INTO post_table_apply (name, comment, date, password) VALUES (:name, :comment, :date, :password)');
        $flag = $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':password' => $password));
        if ($flag){
            print('投稿しました<br>');
        }else{
            print('投稿に失敗しました<br>');
        }
    }else{
        echo "未入力の欄があります<br/>";
    }
}elseif(isset($_POST['comment']) && isset($_POST['name']) && isset($_POST['edit_id'])){
    if(strlen($_POST['comment']) && strlen($_POST['name']) && strlen($_POST['edit_id'])){
        $comment = $_POST['comment'];
        $name = $_POST['name'];
        $date = date("Y-m-d");
        $edit_id = $_POST['edit_id'];
        $stmt = $pdo->prepare("UPDATE post_table_apply SET name = :name, comment = :comment, date = :date WHERE id = :id");
        $stmt->execute(array(':name' => $name, ':comment' => $comment, ':date' => $date, ':id' => $edit_id));
        $edit_id = -10000;
    }else{
        echo "未入力の欄があります<br/>";
    }
}

echo "投稿一覧<br/>";
$result_rows = $pdo->query('SELECT * FROM post_table_apply');
foreach ( $result_rows as $row ) {
    echo "{$row['id']}";
    echo " {$row['name']}";
    echo " {$row['comment']}";
    echo " {$row['date']}";
    echo "<br/>";
}
echo "<br/>";
?>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>投稿フォーム</h1>
    <form action="kadai3_top.php" method="post">
    <p>名前</p>
    <input type = "text" name ="name" value="<?php if(isset($edit_name)){echo $edit_name;} ?>"><br/>
    <p>コメント</p>
    <input type = "text" name ="comment" value="<?php if(isset($edit_txt)){echo $edit_txt;} ?>"><br/>
    <?php if(!isset($edit_id) || $edit_id == -10000){
    ?>
        <p>パスワード</p>
        <input type = "text" name ="password"><br/>
    <?php
    }
    ?>
    <input type="hidden" name ="edit_id" value="<?php if(isset($edit_id)){echo $edit_id;} ?>">
    <input type = "submit" value ="送信">
    </form>
    <script>
    function delete_confirm() {
            var select = confirm("削除してよろしいですか?");
            return select;
    }
    </script>
    <h1>削除</h1>
    <p>削除する投稿の番号</p>
    <form action="kadai3_top.php" method="post" onsubmit="return delete_confirm()">
    <input type = "text" name ="delete"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信">
    </form>
    <h1>編集</h1>
    <p>編集する投稿の番号</p>
    <form action="kadai3_top.php" method="post">
    <input type = "text" name ="edit"><br/>
    <p>パスワード</p>
    <input type = "text" name ="password"><br/>
    <input type = "submit" value ="送信"><br/>
    <a href="http://co-19-271.99sv-coco.com/kadai3_1_signup.php">新規登録</a>
    </form>
</body>
</html>
anonymous No title
JavaScript
あああ
anonymous No title
Python
 
<a href="https://rostovdriver.ru/jeans/">short</a>
anonymous #ぷっくん 神版
Python
import clipboard
import keyboard
import datetime
import sched
import tweepy
import json
import time
import sys
import re

# ルーム番号 
roomid ="0000"
# 時間
passtime = "00"

username = clipboard.get()
password  = ""
consumerkey = "d4Oc6wq45RSEXbs5kzQJ4adQa"
consumersecret = "jC4Mt0pljr0VgI2RcBEeDhWu2EXMRDvwKLzXCc9kARVhWvSfNT"
accesstoken = "1292635670373007360-d3APeAMBN3vBS3grK7kwMfOdOPIc0W"
accesstokensecret = "cJWZNxVIKgnd6Q0JhZ8I6H8gQ9whBkeGjzMGP8ERNqsFM"

Auth = tweepy.OAuthHandler(consumerkey,consumersecret)
Auth.set_access_token(accesstoken,accesstokensecret)
Api = tweepy.API(Auth)

now   = datetime.datetime.now()
minute = now.minute

if("/" in str(username)):
	username = username.split("/")
	username = username[3].split("?")
	username = username[0]
else:
	print("リンクをコピーしてください")
	sys.exit()
for a in range(20):  
  for i in range(20) :
    for i, status in enumerate(tweepy.Cursor(Api.user_timeline,id=username,tweet_mode="extended").items(1)):
    	tweettime = re.findall(r"\d+",str(status.created_at))
    	if( '@' in status.full_text ):
    	  moto = status.full_text
    	  co = moto.index('@')
    	  kore = list(moto)
    	  del kore[co:]
    	  status.full_ta = ''.join(kore)
    	  tweet = re.findall(r"\d+",status.full_ta)
    	else:
  	    tweet = re.findall(r"\d+",status.full_text)

    tweet0 = ''.join(tweet)
    tweet1 = re.findall(r"\d",tweet0) 
  
    if(passtime in tweettime):
    	print("パスワード!")
    else:
    	print("更新速度 爆速!")
    	time.sleep(0.005)
    	break
  	
    if( roomid in tweet0 ):
      keyboard.insert_text(tweet[1])
      keyboard.insert_text("\n")
      print("password:"+tweet[1])
      sys.exit()
    else:
       keyboard.insert_text(tweet[0])
       keyboard.insert_text("\n")
       print("password:"+tweet[0])
       sys.exit()   
anonymous #ぷっくん 神版
Python
import clipboard
import keyboard
import datetime
import sched
import tweepy
import json
import time
import sys
import re

# ルーム番号 
roomid ="0000"
# 時間
passtime = "00"

username = clipboard.get()
password  = ""
consumerkey = "d4Oc6wq45RSEXbs5kzQJ4adQa"
consumersecret = "jC4Mt0pljr0VgI2RcBEeDhWu2EXMRDvwKLzXCc9kARVhWvSfNT"
accesstoken = "1292635670373007360-d3APeAMBN3vBS3grK7kwMfOdOPIc0W"
accesstokensecret = "cJWZNxVIKgnd6Q0JhZ8I6H8gQ9whBkeGjzMGP8ERNqsFM"

Auth = tweepy.OAuthHandler(consumerkey,consumersecret)
Auth.set_access_token(accesstoken,accesstokensecret)
Api = tweepy.API(Auth)

now   = datetime.datetime.now()
minute = now.minute

if("/" in str(username)):
	username = username.split("/")
	username = username[3].split("?")
	username = username[0]
else:
	print("リンクをコピーしてください")
	sys.exit()
for a in range(20):  
  for i in range(20) :
    for i, status in enumerate(tweepy.Cursor(Api.user_timeline,id=username,tweet_mode="extended").items(1)):
    	tweettime = re.findall(r"\d+",str(status.created_at))
    	if( '@' in status.full_text ):
    	  moto = status.full_text
    	  co = moto.index('@')
    	  kore = list(moto)
    	  del kore[co:]
    	  status.full_ta = ''.join(kore)
    	  tweet = re.findall(r"\d+",status.full_ta)
    	else:
  	    tweet = re.findall(r"\d+",status.full_text)

    tweet0 = ''.join(tweet)
    tweet1 = re.findall(r"\d",tweet0) 
  
    if(passtime in tweettime):
    	print("パスワード!")
    else:
    	print("更新速度 爆速!")
    	time.sleep(0.005)
    	break
  	
    if( roomid in tweet0 ):
      keyboard.insert_text(tweet[1])
      keyboard.insert_text("\n")
      print("password:"+tweet[1])
      sys.exit()
    else:
       keyboard.insert_text(tweet[0])
       keyboard.insert_text("\n")
       print("password:"+tweet[0])
       sys.exit()   
anonymous No title
Python
import clipboard
import keyboard
import datetime
import sched
import tweepy
import json
import time
import sys
import re

# ルーム番号 
roomid ="0000"
# 時間
passtime = "00"

username = clipboard.get()
password  = ""
consumerkey = "d4Oc6wq45RSEXbs5kzQJ4adQa"
consumersecret = "jC4Mt0pljr0VgI2RcBEeDhWu2EXMRDvwKLzXCc9kARVhWvSfNT"
accesstoken = "1292635670373007360-d3APeAMBN3vBS3grK7kwMfOdOPIc0W"
accesstokensecret = "cJWZNxVIKgnd6Q0JhZ8I6H8gQ9whBkeGjzMGP8ERNqsFM"

Auth = tweepy.OAuthHandler(consumerkey,consumersecret)
Auth.set_access_token(accesstoken,accesstokensecret)
Api = tweepy.API(Auth)

now   = datetime.datetime.now()
minute = now.minute

if("/" in str(username)):
	username = username.split("/")
	username = username[3].split("?")
	username = username[0]
else:
	print("リンクをコピーしてください")
	sys.exit()
for a in range(20):  
  for i in range(20) :
    for i, status in enumerate(tweepy.Cursor(Api.user_timeline,id=username,tweet_mode="extended").items(1)):
    	tweettime = re.findall(r"\d+",str(status.created_at))
    	if( '@' in status.full_text ):
    	  moto = status.full_text
    	  co = moto.index('@')
    	  kore = list(moto)
    	  del kore[co:]
    	  status.full_ta = ''.join(kore)
    	  tweet = re.findall(r"\d+",status.full_ta)
    	else:
  	    tweet = re.findall(r"\d+",status.full_text)

    tweet0 = ''.join(tweet)
    tweet1 = re.findall(r"\d",tweet0) 
  
    if(passtime in tweettime):
    	print("パスワード!")
    else:
    	print("更新速度 爆速!")
    	time.sleep(0.005)
    	break
  	
    if( roomid in tweet0 ):
      keyboard.insert_text(tweet[1])
      keyboard.insert_text("\n")
      print("password:"+tweet[1])
      sys.exit()
    else:
       keyboard.insert_text(tweet[0])
       keyboard.insert_text("\n")
       print("password:"+tweet[0])
       sys.exit()   
anonymous No title
Python
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Dimension;

import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame {

  public static void main(String[] args){

		SynthAkira akira = new SynthAkira("Synth Akira");
		akira.setVisible(true);
  }

  SynthAkira(String title){
    setTitle(title);
    setBounds(100, 100, 600, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.add(new SynthSlider(), BorderLayout.PAGE_START);
    contentPane.add(new DrawCurve(), BorderLayout.CENTER);
	}
}

class SynthSlider extends JPanel implements ChangeListener {

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JPanel p3;
  	JPanel p4;
  	JButton b1;
  JButton b2;
  JLabel label1;
  JLabel label2;
  
  	static byte[] wave_data = new byte[44100];
  
	SynthSlider() {
		
		slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b1 = new JButton("DOWN");
    b2 = new JButton("UP");
    
    p2 = new JPanel();
    p2.add(b1);
    p2.add(b2);
    
    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p3 = new JPanel();
    p3.add(label1);
    p3.add(label2);

    p4 = new JPanel();
// 		p4.setPreferredSize(new Dimension(600, 400));
    p4.setLayout(new BorderLayout());
    p4.add(p1, BorderLayout.PAGE_START);
    p4.add(p2, BorderLayout.CENTER);
    p4.add(p3, BorderLayout.PAGE_END);

		add(p4);

    b1.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(1);
		  }
		});
    b2.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(2);
		  }
		});
	}

   void setSound(int j){
      try{
          double l1 = j*slider1.getValue()/44100.0;
         double l2 = j*slider2.getValue()/44100.0;
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*(wave_data.length-(i+1))/wave_data.length*Math.sin((i*l1)*Math.PI*2)
            *Math.sin((i*l2)*Math.PI*2));
            			}
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();
	         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
	}
}

class DrawCurve extends JPanel { 

	JButton b1;
	Paint paint;
	JPanel p1;

	DrawCurve() { 

		p1 = new JPanel();
      b1 = new JButton ("PUSH");
     b1.setPreferredSize(new Dimension(100, 30));
      paint = new Paint();
     paint.setPreferredSize(new Dimension(600, 200));
     	p1.setPreferredSize(new Dimension(600, 300));
		p1.add(b1);
		p1.add(paint);
		add(p1);

     b1.addActionListener(new ActionListener() {
	      @Override
	      public void actionPerformed(ActionEvent e) {
		 		paint.repaint();
			}
		}); 
	 } 
}

class Paint extends JPanel {
	
	byte[] wave_data = SynthSlider.wave_data;
	
	public Paint() {
		super();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.RED);
		for(int i = 0; i < (wave_data.length/200-1); i++) {
    			g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
 		}
	}
} 
anonymous No title
Python
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Dimension;

import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame {

  public static void main(String[] args){

		SynthAkira akira = new SynthAkira("Synth Akira");
		akira.setVisible(true);
  }

  SynthAkira(String title){
    setTitle(title);
    setBounds(100, 100, 600, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.add(new SynthSlider(), BorderLayout.PAGE_START);
    contentPane.add(new DrawCurve(), BorderLayout.CENTER);
	}
}

class SynthSlider extends JPanel implements ChangeListener {

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JPanel p3;
  	JPanel p4;
  	JButton b1;
  JButton b2;
  JLabel label1;
  JLabel label2;
  
  	static byte[] wave_data = new byte[44100];
  
	SynthSlider() {
		
		slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b1 = new JButton("DOWN");
    b2 = new JButton("UP");
    
    p2 = new JPanel();
    p2.add(b1);
    p2.add(b2);
    
    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p3 = new JPanel();
    p3.add(label1);
    p3.add(label2);

    p4 = new JPanel();
// 		p4.setPreferredSize(new Dimension(600, 400));
    p4.setLayout(new BorderLayout());
    p4.add(p1, BorderLayout.PAGE_START);
    p4.add(p2, BorderLayout.CENTER);
    p4.add(p3, BorderLayout.PAGE_END);

		add(p4);

    b1.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(1);
		  }
		});
    b2.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(2);
		  }
		});
	}

   void setSound(int j){
      try{
          double l1 = j*slider1.getValue()/44100.0;
         double l2 = j*slider2.getValue()/44100.0;
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*(wave_data.length-(i+1))/wave_data.length*Math.sin((i*l1)*Math.PI*2)
            *Math.sin((i*l2)*Math.PI*2));
            			}
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();
	         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
	}
}

class DrawCurve extends JPanel { 

	JButton b1;
	Paint paint;
	JPanel p1;

	DrawCurve() { 

		p1 = new JPanel();
      b1 = new JButton ("PUSH");
     b1.setPreferredSize(new Dimension(100, 30));
      paint = new Paint();
     paint.setPreferredSize(new Dimension(600, 200));
     	p1.setPreferredSize(new Dimension(600, 300));
		p1.add(b1);
		p1.add(paint);
		add(p1);

     b1.addActionListener(new ActionListener() {
	      @Override
	      public void actionPerformed(ActionEvent e) {
		 		paint.repaint();
			}
		}); 
	 } 
}

class Paint extends JPanel {
	
	byte[] wave_data = SynthSlider.wave_data;
	
	public Paint() {
		super();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.RED);
		for(int i = 0; i < (wave_data.length/200-1); i++) {
    			g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
 		}
	}
} 
anonymous No title
Python
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Dimension;

import java.lang.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.sound.sampled.*;

public class SynthAkira extends JFrame {

  public static void main(String[] args){

		SynthAkira akira = new SynthAkira("Synth Akira");
		akira.setVisible(true);
  }

  SynthAkira(String title){
    setTitle(title);
    setBounds(100, 100, 600, 600);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Container contentPane = getContentPane();
    contentPane.add(new SynthSlider(), BorderLayout.PAGE_START);
    contentPane.add(new DrawCurve(), BorderLayout.CENTER);
	}
}

class SynthSlider extends JPanel implements ChangeListener {

  JSlider slider1;
  JSlider slider2;
  JPanel p1;
  JPanel p2;
  JPanel p3;
  	JPanel p4;
  	JButton b1;
  JButton b2;
  JLabel label1;
  JLabel label2;
  
  	static byte[] wave_data = new byte[44100];
  
	SynthSlider() {
		
		slider1 = new JSlider(0, 1000);
    slider1.setValue(100);
    slider1.addChangeListener(this);
    slider2 = new JSlider(0, 1000);
    slider2.setValue(100);
    slider2.addChangeListener(this);

    p1 = new JPanel();
    p1.add(slider1);
    p1.add(slider2);

    b1 = new JButton("DOWN");
    b2 = new JButton("UP");
    
    p2 = new JPanel();
    p2.add(b1);
    p2.add(b2);
    
    label1 = new JLabel();
    label2 = new JLabel();
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());

    p3 = new JPanel();
    p3.add(label1);
    p3.add(label2);

    p4 = new JPanel();
// 		p4.setPreferredSize(new Dimension(600, 400));
    p4.setLayout(new BorderLayout());
    p4.add(p1, BorderLayout.PAGE_START);
    p4.add(p2, BorderLayout.CENTER);
    p4.add(p3, BorderLayout.PAGE_END);

		add(p4);

    b1.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(1);
		  }
		});
    b2.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
      			setSound(2);
		  }
		});
	}

   void setSound(int j){
      try{
          double l1 = j*slider1.getValue()/44100.0;
         double l2 = j*slider2.getValue()/44100.0;
         for(int i=0;i<wave_data.length;i++){
            wave_data[i]= (byte)(110*(wave_data.length-(i+1))/wave_data.length*Math.sin((i*l1)*Math.PI*2)
            *Math.sin((i*l2)*Math.PI*2));
            			}
         AudioFormat   frmt= new AudioFormat(44100,8,1,true,false);
         DataLine.Info info= new DataLine.Info(Clip.class,frmt);
         Clip          clip= (Clip)AudioSystem.getLine(info);
         clip.open(frmt,wave_data,0,wave_data.length);
         clip.start();
	         }
      catch(Exception e){e.printStackTrace(System.err);}
      }

	public void stateChanged(ChangeEvent e) {
    label1.setText("値:" + slider1.getValue());
    label2.setText("値:" + slider2.getValue());
	}
}

class DrawCurve extends JPanel { 

	JButton b1;
	Paint paint;
	JPanel p1;

	DrawCurve() { 

		p1 = new JPanel();
      b1 = new JButton ("PUSH");
     b1.setPreferredSize(new Dimension(100, 30));
      paint = new Paint();
     paint.setPreferredSize(new Dimension(600, 200));
     	p1.setPreferredSize(new Dimension(600, 300));
		p1.add(b1);
		p1.add(paint);
		add(p1);

     b1.addActionListener(new ActionListener() {
	      @Override
	      public void actionPerformed(ActionEvent e) {
		 		paint.repaint();
			}
		}); 
	 } 
}

class Paint extends JPanel {
	
	byte[] wave_data = SynthSlider.wave_data;
	
	public Paint() {
		super();
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setColor(Color.RED);
		for(int i = 0; i < (wave_data.length/200-1); i++) {
    			g.drawLine(i*2,128-wave_data[i*200],(i+1)*2,128-wave_data[(i+1)*200]);
 		}
	}
}