기본 콘텐츠로 건너뛰기

2018의 게시물 표시

Java Swing Example 411 TextArea And TextField

package pages ; import javax.swing.* ; import java.awt.* ; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class page411 extends JFrame { private JTextField tf = new JTextField( 20 ) ; private JTextArea ta = new JTextArea( 7 , 20 ) ; public page411 (){ setTitle( "TextArea Example" ) ; setDefaultCloseOperation( EXIT_ON_CLOSE ) ; Container c = getContentPane() ; c.setLayout( new FlowLayout()) ; c.add( new JLabel( "Press Enter after input entry" )) ; c.add( tf ) ; c.add( new JScrollPane( ta )) ; tf .addActionListener( new ActionListener() { @Override public void actionPerformed (ActionEvent e) { JTextField t = (JTextField)e.getSource() ; //getting a source to mention the object it is listening to ta .append(t.getText() + " \n " ) ; //t.getText gets user text i

Java Swing Example 409 JTextField + JLabel

package pages ; import javax.swing.* ; import java.awt.* ; public class page409 extends JFrame { public page409 (){ setTitle( "TextField Example" ) ; setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE ) ; Container c = getContentPane() ; c.setLayout( new FlowLayout()) ; c.add( new JLabel( "Name " )) ; c.add( new JTextField( 20 )) ; c.add( new JLabel( "Major " )) ; c.add( new JTextField( "Computer Science" , 20 )) ; c.add( new JLabel( "Address " )) ; c.add( new JTextField( "Earth" , 20 )) ; setSize( 300 , 150 ) ; setVisible( true ) ; } public static void main (String[] args){ new page409() ; } } //label means small component for text //textField means textArea to get an user input

Java Propagater - Catcher ex5 IsPrime??

import java.util.Scanner ; class PrimeChecker { public boolean isPrime ( int input) { for ( int i = 2 ; i < input ; i++) { if (input % i == 0 ) { return false; } } return true; } } public class ex5 { public static void main (String [] args){ Scanner in = new Scanner(System. in ) ; PrimeChecker pc = new PrimeChecker() ; while ( true ){ try { int input = Integer. parseInt (in.nextLine()) ; if (input < 0 ) break; else if (pc.isPrime(input) == false ) throw new Exception( "Not a prime" ) ; System. out .println(input + " is a prime number" ) ; } catch (Exception e) { System. out .println( "Not a prime" ) ; } } System. out .println( "Terminated" ) ; } }

Java starDrawing ex4

import java.util.Scanner ; public class ex4 { public static void main (String[] args) { Scanner in = new Scanner(System. in ) ; int input = - 1 ; while ( true ){ try { input = Integer. parseInt (in.nextLine()) ; //if(input == 0 || input % 2 == 0) if (input == 0 ) break; else if ( input % 2 == 0 ) throw new Exception( "Not an odd number" ) ; for ( int y = 0 ; y < input ; y++){ for ( int x = 0 ; x < input ; x++){ if (((x <= y) && (x <= (input-y- 1 )))||(x >= y) && (x >= (input-y- 1 ))) System. out .print( "*" ) ; else System. out .print( " " ) ; } System. out .println() ; } System. out .print

Java Swing Example 396 Hi Gosling!

package pages ; import javax.swing.* ; import java.awt.* ; public class page396 extends JFrame{ public page396 (){ setTitle( "Label example" ) ; setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE ) ; Container c = getContentPane() ; c.setLayout( new FlowLayout()) ; JLabel textLabel = new JLabel( "I am James Gosling" ) ; ImageIcon img = new ImageIcon( "C: \\ Users \\ hm970 \\ IdeaProjects \\ BjavaSwingPrac" + " \\ src \\ pages \\ imgs \\ gosling.png" ) ; JLabel imageLabel = new JLabel(img) ; ImageIcon icon = new ImageIcon( "C: \\ Users \\ hm970 \\ IdeaProjects \\ BjavaSwingPrac" + " \\ src \\ pages \\ imgs \\ phone.png" ) ; JLabel label = new JLabel( "Would you like to have a coffee?" + " just call me" , icon , SwingConstants. CENTER ) ; c.add(textLabel) ;

Java Swing Example 373 KeyListener

package pages.imgs ; import javax.swing.* ; import java.awt.* ; import java.awt.event.KeyAdapter ; import java.awt.event.KeyEvent ; public class page373_4 extends JFrame { private JLabel la = new JLabel( "changes backgroundcolor by enter" ) ; public page373_4 (){ super ( "Keylistener's character key input example" ) ; setDefaultCloseOperation( EXIT_ON_CLOSE ) ; Container c = getContentPane() ; c.setLayout( new FlowLayout()) ; c.add( la ) ; // adding a label to a default pan c.addKeyListener( new MyKeyListener()) ; setSize( 250 , 150 ) ; setVisible( true ) ; c.setFocusable( true ) ; // allowing content pan to have a focus,,,??? c.requestFocus() ; //setting a focus to a pan } class MyKeyListener extends KeyAdapter{ public void keyPressed (KeyEvent e){ int r = ( int ) (Math. random () * 256 ) ; int g = ( int ) (Math. random () * 25

Damned Star Drawing With Loop / Try Catch

import java.util.Scanner ; public class ex4 { public static void main (String[] args) { Scanner in = new Scanner(System. in ) ; int input = - 1 ; do { try { input = Integer. parseInt (in.nextLine()) ; if (input == 0 || input % 2 == 0 ) throw new Exception( "Put an even and positive number" ) ; for ( int y = 0 ; y < input ; y++){ for ( int x = 0 ; x < input ; x++){ if (((x <= y) && (x <= (input-y- 1 )))||(x >= y) && (x >= (input-y- 1 ))) System. out .print( "*" ) ; else System. out .print( " " ) ; } System. out .println() ; } System. out .println() ; } catch (Exception e){ System. o

Java subString and simple swing - Monogram

import javax.swing.* ; public class Ch2Monogram { public static void main (String [] args){ // String name; // // name = JOptionPane.showInputDialog(null, // "Enter your full name(First, middle, last : "); // // JOptionPane.showMessageDialog(null, name); String name , first , middle , last , space , monogram ; space = " " ; //showInoutDialog -> window with textArea name = JOptionPane. showInputDialog ( null, "Enter your full name (first, middle, last):" ) ; //Extract first, middle, and last names first = name.substring( 0 , name.indexOf(space)) ; name = name.substring(name.indexOf(space)+ 1 , name.length()) ; middle = name.substring( 0 , name.indexOf(space)) ; last = name.substring(name.indexOf(space)+ 1 , name.length()) ; //Compute the monogram monogram = first.substring( 0 , 1 ) + middle.substri

5.4 task Sum input numbers

<!DOCTYPE HTML> <html>   <body>   </body>   <Script>    "use strict"; function  sumInput(){   let nums = [];   while(true){     let val = prompt("A number plz?", 0);     //should we cancel?     //valu should stay as String during the input     //to distinguish an empty String     if( val === "" || !isFinite(val) || val === null ) {       alert (val);       break;     }     //val === "" for preventing an empty input     //val === null for when the cancel button was pressed in prompt window     // !isFinite(val) I dont know....     //isFinite returns true when the val is +infinity, -infinity, or NaN     //isFinite is to catch an NaN which occurs from empty input     nums.push(+val);//   }   let sum = 0;   for (let num of nums){     sum += num;   }   return sum; } /* my trial was... let sum; let val; while(true){   let val = +prompt("Value?", );   if(typeof val != &quo

Quick Sort

#include <stdio.h> void display(int arr[], int LEN){ printf("The sorted array is:\n"); for(int i = 0; i < LEN; i++){ printf("%d ", arr[i]); } } void swap(int num1, int num2, int arr[]){ int tmp = arr[num1]; arr[num1] = arr[num2]; arr[num2] = tmp; } int wallMove (int left, int right, int pivot, int arr[], int LEN){ int leftP = left - 1; int rightP = right; while (1){ while(arr[++leftP] < pivot) { //do nothing }//after while statement, left lines are continued while(rightP > 0 && arr[--rightP] > pivot) { //do nothing } if(leftP >= rightP){ break; } else { // leftp > pivot et leftP < rightP printf(" item swapped : %d, %d\n", arr[leftP], arr[rightP]); swap(leftP, rightP, arr); } } printf(" pivot swapped : %d, %d \n", arr[leftP], arr[right]); swap(leftP, right, arr); printf("updated Array : "); display(arr, LEN)

Counting Sort

#include <stdio.h> #define MAX 18 #define bill 4 //void swap(int idx1, int idx2, int arr[]){ // int tmp = arr[idx1]; // arr[idx1] = arr[idx2]; // arr[idx2] = tmp; //} void print(int arr[]){ printf("\nThe sorted array is:\n"); for(int i = 0; i < MAX; i++){ printf("%d ", arr[i]); } printf("\n"); } int main(){ int arr[MAX] = {1000, 10000, 50000, 1000, 10000, 5000, 1000, 5000, 50000, 1000, 5000, 10000, 1000, 5000, 10000, 10000, 1000, 50000}; int std[4] = {1000, 5000, 10000, 50000}; int num[4] = {0}; for(int i = 0; i < MAX; i++){ if(arr[i] == std[0]){ num[0]++; } if(arr[i] == std[1]){ num[1]++; } if(arr[i] == std[2]){ num[2]++; } if(arr[i] == std[3]){ num[3]++; } } printf("There are %d 1000 won bills\n", num[0]); printf("There are %d 5000 won bills\n", num[1]); printf("There are %d 10,000 won bills\n", num[2]);

Late Night Last Night

Probably this sentence will be the most spoken one this year. "I feel so different everyday. A day, a week and a month feel so different.." Yesterday I made decision that I could not had done it if I were me few months ago. And the result was very satisfying. Also I've been trying to let me be in new type of flow and do not feel insecure. Last Night Late Night I could get home at a time I wanted from a party. I consider it as succeeding of listening to myself which I've been trying real hard to achieve. I feel I'm doing great!

5.4 Arrays task Calling In an Array Context

  <Script>  "use strict"; let arr = ["a", "b"]; arr.push( function () {   alert(this); }) //it pushes an object which is function at arr[2] //but why does the function contains a and b? because of this? //what "this" means? the whole array? is that why? //oh maybe it should arr[2](); //but why line 17 shows even the contents of the function?   </Script>

Sorting - Insertion

#include <stdio.h> #include <stdlib.h> #define INDEX 11 int main(){ const int index = 10;   int arr[INDEX] = {88, 55, 24, 1, 6, 35, 78, 56, 100, 11, 1}; for(int i = 0; i < INDEX; i++){ //traverse unsorted part int temp = arr[i]; //compare with the latest sorted element int j = i - 1; // j = sorted indexs //temp = element to put in sorted part //repeat till sorted part index is smaller or same as i while(temp < arr[j] && j >= 0){ //first j + 1 means arr[i] //while excution means couldnt find right place //thus sorted element part should move one cells to right side arr[j + 1] = arr[j]; //reverse traversal j--; } //when finally j + 1 is right place //while finished -> should ++ to point proper j //or no while excution -> it is in order => stay where u r arr[j+1] = temp; } printf("The sorted array is:\n"); for(int i = 0; i < 11;

5.3 task Extract Money

  <Script>  "use strict"; //dollorsign iin hexa = "\u0024" function extractCurrencyValue (str){   let target = "\u0024";   let pos = -1;   while ( (pos = str.indexOf(target, pos + 1)) != -1 ){   //  alert(pos);     if(pos == 0){       return (+str.slice(1));     }     else {       return (+str.substring(str.length - 1, 0) );     }   } } alert(extractCurrencyValue('120$') === 120);   </Script>

5.3 task Truncate The Text

<!DOCTYPE html> <html> <body>   <Script>  "use strict"; function truncate (str, maxlength){   if(str.length >= maxlength){     alert(str.substring(0,maxlength) + "...");   }   else alert(str); }   truncate("What I'd like to tell on this topic is:", 20);   truncate("Hi everyone!", 20);   </Script> </body> </html>

God damn Star Drawing

import java.util.Scanner ; public class ex2 { public static void main (String[] arg){ Scanner in = new Scanner(System. in ) ; int input = in.nextInt() ; for ( int i = 0 ; i < input ; i++){ for ( int j = 0 ; j <= i ; j++){ System. out .print( "*" ) ; } System. out .println( "" ) ; } for ( int i = input - 1 ; i> 0 ; i--){ // runs n-1 times for ( int j = 0 ; j < i ; j++){ System. out .print( "*" ) ; } System. out .print( " \n " ) ; } } } //이젠 멈춰주세요..제발....

4.4 task Calculator

4.4 task <script> "use strict" let calculator = { // input1 : 0, // input2 : 0, //do not need new value definition //such an amazing language it is...!!! read() { this.input1 = +prompt('Input first operand', ); this.input2 = +prompt("Input second operand", ); /////////////to make the input to be INTEGER WE NEED THIS + }, sum(){ return this.input1 + this.input2; }, mul(){ return this.input1 * this.input2; }, }; calculator.read(); alert(calculator.sum() ); alert(calculator.mul() ); </script>

4.4 task Chained Function

4.4 task chain <script> "use strict" let ladder = { step: 0, up() { this.step++; return this; }, down() { this.step--; return this; }, showStep: function() { // shows the current step alert( this.step ); } }; ladder.up().up().down().showStep(); </script>

5.3 task - Blocking spam

<!DOCTYPE html> <html> <body>   <Script> function checkSpam(str){   str = str.toLowerCase();   let tar1 = "xxx";   let tar2 = "viagra";   let pos = -1;   while( (pos = str.indexOf(tar1, pos + 1) != -1) ){     //condition means when it found     return true;   }   pos = -1;   while( (pos = str.indexOf(tar2, pos + 1) != -1) ){     //condition means when it found     return true;   } return false; }  alert(checkSpam('innocent Rabbit') );   </Script> </body> </html>

Sorting - Selection

#include <stdio.h> //writer 5396952 Hyeonmin LEE #include <stdlib.h> #define INDEX 11 int main(){ const int index = 10;   int arr[INDEX] = {88, 55, 24, 1, 6, 35, 78, 56, 100, 11, 1}; int small; int temp; for(int n = 0; n < 11; n++){ small = n; for(int i = n; i < 11; i++){ if(arr[small] > arr[i]){ small = i; } } temp = arr[n]; arr[n] = arr[small]; arr[small] = temp; } printf("The sorted array is:\n"); for(int i = 0; i < 11; i++){ printf("%d", arr[i]); if(i != 10){ printf(" "); } else printf("\n"); } return 0; }

Sorting - Buble

#include <stdio.h> //writer 5396952 Hyeonmin LEE #include <stdlib.h> #define INDEX 11 int main(){ const int index = 10;   int arr[INDEX] = {88, 55, 24, 1, 6, 35, 78, 56, 100, 11, 1}; int temp; for(int i = 0; i < 9; i++){ for (int j = 0; j < 10; j++) { while(arr[j] > arr[j+1]){ temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } printf("The sorted array is:\n"); for(int i = 0; i < 11; i++){ printf("%d", arr[i]); if(i != 10){ printf(" "); } else printf("\n"); } return 0; }

Heap

#include <stdio.h> #include <stdlib.h> #include <math.h> #include <stdbool.h> #define MAXSIZE 10 typedef struct { int heapAry[MAXSIZE]; int last; int size; int maxSize; }HEAP; HEAP* heapCreate (int maxSize){ HEAP *heap = (HEAP*)malloc (sizeof (HEAP)); if(!heap) return NULL; heap->last = -1; //the index (works as top in stack) heap->size = 0; //wtf? heap->maxSize = (int) pow(2, ceil(log2(maxSize))) - 1; //force heap size to power of 2-1 int array[maxSize]; //allocate the array[maxSize] times size of void* return heap; } void reheapUp(HEAP* heap, int childLoc){ int parent = 0; // start a traverse from the parent int hold = 0; //if child is root node, right goes to return if(childLoc){ //if the child is not null == not root node parent = (childLoc - 1) / 2; if(heap->heapAry[childLoc] > heap->heapAry[parent]){ //if compare returns 1 or true, //it means child is bigger than par

Summer works in Vancouver, BC

Tried to catch the night seeing but....:(   I couldn't just pass by these flowers. It was much beautiful and bright than it seems . Tried to catch this city's own feeling. like the reflection on the windows and that road signs written streets' name Morning rainbow came onto the wall of the hotel and onto me Grab the handle and grab the light given to u which is precious present to go down the floor It was beautiful street in the Gastown Vancouver wish I could really capture this scene :( To melt u down from whatever frozed u. Believe me, no matter what, positivity is the right way and love is the answer. A memorial bench in Hallelujah Point, Stanley Park, Vancouver, BC  Dear, you will be always at the center, the most important, precious one in this cruel world Wanted to capture those flowers seen through the wooden fence. Easily could see so petit bunch of flowers in Vancouver walking the streets!