기본 콘텐츠로 건너뛰기

11월, 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!