Jump to content

The under 100 line challenge!

fletch to 99


import easygui as eg #imports easygui library with the variable eg assigned
import random #imports random library as random
import sys # imports system library/module as sys

def magicNum():
    randNum = random.randrange(1,101)
    #decision=eg.msgbox(randNum,'Magic Number Game') #This line of code will provide the guess before the game begins, for testing purposes.
    attempt = 1
    guess = 0
    
    title=eg.ccbox(msg="Welcome to the Magic Number Game!\n\n-You must guess what number i am thinking of\n(HINT - IT IS SOMEWHERE BETWEEN 1 & 100)\n-You must guess it in as few attempts as possible", title="Welcome to the Magic Number Game!", choices=("Play Now", "Exit"), image=None)
    if title==0: #if user selects "Exit" from the title box, the program will close.
        sys.exit()
    
    while guess != randNum:
        guess=eg.integerbox( msg='Enter a number between 1 and 100',
        title='Magic Number Game', default='', lowerbound=1, upperbound=100)
        if guess == None: #If user selects "Cancel" from the guess box, the program will close.
            sys.exit()
            
        if guess==randNum:
            answer = eg.buttonbox("You have guessed correctly! it took you "+str(attempt)+' attempt(s)\nWould you like to play again?', choices=["Yes","No"], title='You Guessed Correctly!')
            if answer == "Yes":
                magicNum() #Calls magicNum function once more to restart game
                guess = 0  #resets guess to 0 for the new game
            else:   
                break
            sys.exit() #closes the program if they do not choose yes
        
        elif guess>randNum:
            high=eg.msgbox('The number is lower','Hmm.. Not Quite', ok_button='Try Again') # if the guess is larger than the random number, this line is called
        
        elif guess<randNum:
            low=eg.msgbox('The number is higher','Hmm.. Not Quite', ok_button='Try Again') # if the guess is less than the random number, this line is called

        attempt +=1 # this line adds 1 attempt to the 'attempt' variable each time a guess is taken.

if __name__ == '__main__':
    magicNum() #End of Magic Number Function

 

 

My entry - the usefulness of this is debatable. Requires an external library called easygui to run.

Dell Certified Engineer | Lenovo Qualified Service Technician | Toshiba Qualified Service Technician

CCENT Qualified Networking Technician

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...
On 2/15/2014 at 5:26 PM, TheUnknown said:

 

 

EDIT-

I forgot to mention that it is coded in C++.Btw it supports all Operating systems(Windows,Linux,Mac or any other os out there)


 #include <iostream>using namespace std;int factorialfinder(int x){    if(x==1){        return 1;    }else{        return x*factorialfinder(x-1);    }}int main(){    int answer,num3;    double num2;    char ans;    float pans = 0;    do{    float num2total = 0,num3total = 1;    int countt = 0;    cout << "CalculatorxPro by <TheUnknown>               Previous result: "<< pans << endl;    cout<< "Main menu:" << endl;    cout << endl;    cout << "Insert:"<< endl;    cout << "1. for [+]"<< endl;    cout << "2. for [-]"<< endl;    cout << "3. for [*]"<<endl;    cout << "4. for [/]"<<endl;    cout << "5. for [Average]"<<endl;    cout <<"6. for [Factorial Finder]"<<endl;    cout <<"7. for [odd,even Checker]" << endl;    cout << endl;    cout <<"Answer: ";    cin >> answer;    cout << string (100,'\n');    switch(answer){    case 1:        cout<<"CalculatorxPro by <Unknown>               Previous result: "<< pans << endl;        pans = 0;        cout <<"Operation [+]" << endl;        cout << endl;        cout << "Insert integers seperated with 'enter' (0 to exit)" << endl;        while((cin >> num2) && num2!=0){            num2total = num2 + num2total;        }        pans = pans + num2total;        cout << "Result: " << num2total << endl;        break;    case 2:                cout<<"CalculatorxPro by <Unknown>               Previous result: "<< pans << endl;        cout <<"Operation [-]" << endl;        pans = 0;        cout << endl;        cout << "Insert integers seperated with 'enter' (0 to exit)" <<endl;        cin >> num2;        if(num2 == 0){            cout << "Result: 0" << endl;            break;        }        num2total = num2 + num2total;        while( (cin >> num2) && num2!=0){                num2total = num2total - num2;        }        pans = pans + num2total;        cout << "Result: " << num2total << endl;        break;    case 3:                cout<<"CalculatorxPro by <Unknown>               Previous result: "<< pans << endl;        cout <<"Operation [*]" << endl;        pans = 0;        cout << endl;        cout << "Insert integers seperated with 'enter' (0 to exit)" << endl;        while( (cin >> num2) && num2!=0){            num3total = num2 * num3total;        }        pans = pans+num3total;        cout << "Result: " << num3total <<endl;        break;    case 4:                cout<<"CalculatorxPro by <Unknown>               Previous result: "<< pans << endl;        cout <<"Operation [/]" << endl;        pans = 0;        cout << endl;        cout << "Insert integers seperated with 'enter' (0 to exit)" << endl;        cin >> num2;        if(num2 == 0){            cout << "Result: 0" << endl;            break;        }        num3total = num2 / num3total;        while( (cin >> num2) && num2!=0){        num3total = num3total / num2;  }        pans = pans+num3total;        cout << "Result: " << num3total <<endl;        break;    case 5:                cout<<"CalculatorxPro by <Unknown>               Previous result: "<< pans << endl;        cout <<"Operation [average]" << endl;        pans = 0;        cout << endl;        cout << "Insert integers seperated with 'enter' (0 to exit)" << endl;        while((cin >> num2) && num2!=0){            num2total = num2total + num2;            countt++;        }        cout << "Numbers entered " << countt << endl;        pans = pans+(num2total/countt);        cout << "Average of the numbers entered " << num2total/countt << endl;        cout <<endl;        break;    case 6:        cout<<"CalculatorxPro by <Unknown>               Previous result: "<< pans << endl;        cout <<"Operation [Factorial Finder]" << endl;        pans = 0;        cout << endl;        cout << "Insert a number [maximum number 16]" << endl;        cin >> num2;        if(16>=num2){            cout << "!" << factorialfinder(num2) << endl;            pans = pans + factorialfinder(num2);            }else{            cout << "Smaller than 16!" << endl;            }        break;    case 7:        cout<<"You selected 7 for [odd,even Checker]" << endl;        cout << endl;        cout << "Enter a number: (0 to exit)" << endl;        while(cin >> num3 && num3!=0){            if((num3%2)==0){                    cout << "Number is even!" << endl;                    cout << "Enter a number: (0 to exit)" << endl;            }else{                cout << "Number is odd!" << endl;                cout << "Enter a number: (0 to exit)" << endl;            }        }        break;     default:        cout <<"Wrong answer!" << endl;    }    cout << "Do you want to continue (y/n)?" <<endl;    cin >> ans;    cout << string(100,'\n');    }    while(ans=='y');    return 0;}

C++ does not support all Operating Systems, unlike what your teachers tell you.

 

You must compile it for a specific platform to work on that platform.

You did a nice job.

Link to comment
Share on other sites

Link to post
Share on other sites

Just a module for interactive frames, it could do with some optimization but meh, I had to minimize it down from 130+ lines, apparently I had some redundant code that could be removed.

// Michael's Interactive Frames Module, designed to function under Sphere 1.5 API.
// Claim this is yours, and ooky spooky skeletons will seal your doom tonight!

var window = function window (width, height, color1, color2, title) {
	this.title = title
	this.posX = 0; this.posY = 0
	
	this.width = width; this.height = height
	
	this.color1 = color1; this.color2 = color2
	
	this.clicked = false
	this.offset = [0, 0]
		
	this.img = CreateSurface (this.width, this.height, CreateColor(0,0,0,0));
	
	this.img.line(0, 0, this.width - 1, 0, this.color1);
	this.img.line(this.width - 1, 0, this.width - 1, this.height - 1, this.color1);
	this.img.line(this.width - 1, this.height -1, 0, this.height - 1, this.color1);
	this.img.line(0, this.height - 1, 0, 0, this.color1);
	this.img.rectangle(1, 20, this.width - 2, this.height - 21, color2);

	this.mcX = 0; this.mcY = 0;
	
	this.boundaries = [0, 0, this.width - 1, 20]
	
	this.objects = new Array();
	
	var a = 0
	for (a = 0; a < 20; a ++) {
		this.img.line(0, a, this.width - 1, a, this.color1);
	}
}

window.prototype = {}

window.prototype.render = function render (active) { // Renders and controls mouse interactions with window.
	if (active) {
		// Store current cursor position to cache
		mX = GetMouseX(); mY = GetMouseY();
		
    var hover = false	// Set hover status to false
		
    if (mX > this.boundaries[0] + this.posX) { //Check if cursor is within boundaries on X axis.
			if (mX < this.boundaries[2] + this.posX) {
				//check if cursor with boundaries on Y axis.
				if (mY > this.boundaries[1] + this.posY) {
					if (mY < this.boundaries[3] + this.posY) {
						hover = true
					}
				}
			}
		}
 
		if (IsMouseButtonPressed(MOUSE_LEFT) == true) { //Set clicked status to true if clicked and status not already true
			if (this.clicked != true) {
				this.clicked = true;
			}
		}
		else {
			if (this.clicked != false) {
				this.clicked = false
			}
		}

		var cache = [this.posX, this.posY] 		//Store window position to cache if clicked.
		if (this.clicked) {
			if (hover) {
				if (this.offset[0] == 0) {
					this.offset[0] = Math.abs(cache[0] - mX);
					this.offset[1] = Math.abs(cache[1] - mY);
				}
			}
			if (this.offset[0] !=0) {
				this.posX = mX - this.offset[0]; this.posY = mY - this.offset[1]
			}
		}
		else if (this.offset[0] != 0) {
			this.offset[0] = 0; this.offset[1] = 0
		}
	}
	
	this.img.blit(this.posX, this.posY);
	GetSystemFont().drawText(this.posX + 4, this.posY + 4, this.title);

	if (this.objects.length > 0) { //Blit new objects to screen
		for (var i = 0; i < this.objects.length; ++i) {
			this.objects[i].render(this.posX, this.posY + 20)
		}
	}
}

window.prototype.move = function move (x, y) {
	this.posX = x;	this.posY = y
}

window.prototype.insert = function insert (object) {
	this.objects.push(object);
}

EDIT: Forgot to mention this is written in JavaScript

My procrastination is the bane of my existence.

I make games and stuff in my spare time.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

I challenged a friend to find the sum of all multiples of 3 or 5 below 1000. He challenged me back by saying that I should do it without any loops or recursion (he's not the best programmer ever, and didn't think that this challenge was possible). So, rather than writing out all of the multiples of 3 or 5 below 1000 as literals, I built a program to write the program for me. Here's the program that does the writing:

 

outfile = open("unrolled_multiples.txt", "w")
list_string = "my_list = [3"

my_length = 0

for i in range(4, 1001):
    if (i % 3 == 0) or (i % 5 == 0):
        list_string = "{old}, {new}" .format(old=list_string, new=str(i))
        my_length += 1

list_string = "{old}]" .format(old=list_string)
outfile.write(list_string)

sum_string = "my_sum = my_list[0]"

for i in range(1, my_length):
    sum_string = "{old} + my_list[{new}]" .format(old=sum_string, new=str(i))

outfile.write("\n{sum}" .format(sum=sum_string))
outfile.write("\nprint(my_sum)")
outfile.write("\n")

 

The output of this program is a text file that looks like this:
 

my_list = [3, 5, 6, 9, 10, 12, 15, 18, 20, 21, 24, 25, 27, 30, 33, 35, 36, 39, 40, 42, 45, 48, 50, 51, 54, 55, 57, 60, 63, 65, 66, 69, 70, 72, 75, 78, 80, 81, 84, 85, 87, 90, 93, 95, 96, 99, 100, 102, 105, 108, 110, 111, 114, 115, 117, 120, 123, 125, 126, 129, 130, 132, 135, 138, 140, 141, 144, 145, 147, 150, 153, 155, 156, 159, 160, 162, 165, 168, 170, 171, 174, 175, 177, 180, 183, 185, 186, 189, 190, 192, 195, 198, 200, 201, 204, 205, 207, 210, 213, 215, 216, 219, 220, 222, 225, 228, 230, 231, 234, 235, 237, 240, 243, 245, 246, 249, 250, 252, 255, 258, 260, 261, 264, 265, 267, 270, 273, 275, 276, 279, 280, 282, 285, 288, 290, 291, 294, 295, 297, 300, 303, 305, 306, 309, 310, 312, 315, 318, 320, 321, 324, 325, 327, 330, 333, 335, 336, 339, 340, 342, 345, 348, 350, 351, 354, 355, 357, 360, 363, 365, 366, 369, 370, 372, 375, 378, 380, 381, 384, 385, 387, 390, 393, 395, 396, 399, 400, 402, 405, 408, 410, 411, 414, 415, 417, 420, 423, 425, 426, 429, 430, 432, 435, 438, 440, 441, 444, 445, 447, 450, 453, 455, 456, 459, 460, 462, 465, 468, 470, 471, 474, 475, 477, 480, 483, 485, 486, 489, 490, 492, 495, 498, 500, 501, 504, 505, 507, 510, 513, 515, 516, 519, 520, 522, 525, 528, 530, 531, 534, 535, 537, 540, 543, 545, 546, 549, 550, 552, 555, 558, 560, 561, 564, 565, 567, 570, 573, 575, 576, 579, 580, 582, 585, 588, 590, 591, 594, 595, 597, 600, 603, 605, 606, 609, 610, 612, 615, 618, 620, 621, 624, 625, 627, 630, 633, 635, 636, 639, 640, 642, 645, 648, 650, 651, 654, 655, 657, 660, 663, 665, 666, 669, 670, 672, 675, 678, 680, 681, 684, 685, 687, 690, 693, 695, 696, 699, 700, 702, 705, 708, 710, 711, 714, 715, 717, 720, 723, 725, 726, 729, 730, 732, 735, 738, 740, 741, 744, 745, 747, 750, 753, 755, 756, 759, 760, 762, 765, 768, 770, 771, 774, 775, 777, 780, 783, 785, 786, 789, 790, 792, 795, 798, 800, 801, 804, 805, 807, 810, 813, 815, 816, 819, 820, 822, 825, 828, 830, 831, 834, 835, 837, 840, 843, 845, 846, 849, 850, 852, 855, 858, 860, 861, 864, 865, 867, 870, 873, 875, 876, 879, 880, 882, 885, 888, 890, 891, 894, 895, 897, 900, 903, 905, 906, 909, 910, 912, 915, 918, 920, 921, 924, 925, 927, 930, 933, 935, 936, 939, 940, 942, 945, 948, 950, 951, 954, 955, 957, 960, 963, 965, 966, 969, 970, 972, 975, 978, 980, 981, 984, 985, 987, 990, 993, 995, 996, 999, 1000]
my_sum = my_list[0] + my_list[1] + my_list[2] + my_list[3] + my_list[4] + my_list[5] + my_list[6] + my_list[7] + my_list[8] + my_list[9] + my_list[10] + my_list[11] + my_list[12] + my_list[13] + my_list[14] + my_list[15] + my_list[16] + my_list[17] + my_list[18] + my_list[19] + my_list[20] + my_list[21] + my_list[22] + my_list[23] + my_list[24] + my_list[25] + my_list[26] + my_list[27] + my_list[28] + my_list[29] + my_list[30] + my_list[31] + my_list[32] + my_list[33] + my_list[34] + my_list[35] + my_list[36] + my_list[37] + my_list[38] + my_list[39] + my_list[40] + my_list[41] + my_list[42] + my_list[43] + my_list[44] + my_list[45] + my_list[46] + my_list[47] + my_list[48] + my_list[49] + my_list[50] + my_list[51] + my_list[52] + my_list[53] + my_list[54] + my_list[55] + my_list[56] + my_list[57] + my_list[58] + my_list[59] + my_list[60] + my_list[61] + my_list[62] + my_list[63] + my_list[64] + my_list[65] + my_list[66] + my_list[67] + my_list[68] + my_list[69] + my_list[70] + my_list[71] + my_list[72] + my_list[73] + my_list[74] + my_list[75] + my_list[76] + my_list[77] + my_list[78] + my_list[79] + my_list[80] + my_list[81] + my_list[82] + my_list[83] + my_list[84] + my_list[85] + my_list[86] + my_list[87] + my_list[88] + my_list[89] + my_list[90] + my_list[91] + my_list[92] + my_list[93] + my_list[94] + my_list[95] + my_list[96] + my_list[97] + my_list[98] + my_list[99] + my_list[100] + my_list[101] + my_list[102] + my_list[103] + my_list[104] + my_list[105] + my_list[106] + my_list[107] + my_list[108] + my_list[109] + my_list[110] + my_list[111] + my_list[112] + my_list[113] + my_list[114] + my_list[115] + my_list[116] + my_list[117] + my_list[118] + my_list[119] + my_list[120] + my_list[121] + my_list[122] + my_list[123] + my_list[124] + my_list[125] + my_list[126] + my_list[127] + my_list[128] + my_list[129] + my_list[130] + my_list[131] + my_list[132] + my_list[133] + my_list[134] + my_list[135] + my_list[136] + my_list[137] + my_list[138] + my_list[139] + my_list[140] + my_list[141] + my_list[142] + my_list[143] + my_list[144] + my_list[145] + my_list[146] + my_list[147] + my_list[148] + my_list[149] + my_list[150] + my_list[151] + my_list[152] + my_list[153] + my_list[154] + my_list[155] + my_list[156] + my_list[157] + my_list[158] + my_list[159] + my_list[160] + my_list[161] + my_list[162] + my_list[163] + my_list[164] + my_list[165] + my_list[166] + my_list[167] + my_list[168] + my_list[169] + my_list[170] + my_list[171] + my_list[172] + my_list[173] + my_list[174] + my_list[175] + my_list[176] + my_list[177] + my_list[178] + my_list[179] + my_list[180] + my_list[181] + my_list[182] + my_list[183] + my_list[184] + my_list[185] + my_list[186] + my_list[187] + my_list[188] + my_list[189] + my_list[190] + my_list[191] + my_list[192] + my_list[193] + my_list[194] + my_list[195] + my_list[196] + my_list[197] + my_list[198] + my_list[199] + my_list[200] + my_list[201] + my_list[202] + my_list[203] + my_list[204] + my_list[205] + my_list[206] + my_list[207] + my_list[208] + my_list[209] + my_list[210] + my_list[211] + my_list[212] + my_list[213] + my_list[214] + my_list[215] + my_list[216] + my_list[217] + my_list[218] + my_list[219] + my_list[220] + my_list[221] + my_list[222] + my_list[223] + my_list[224] + my_list[225] + my_list[226] + my_list[227] + my_list[228] + my_list[229] + my_list[230] + my_list[231] + my_list[232] + my_list[233] + my_list[234] + my_list[235] + my_list[236] + my_list[237] + my_list[238] + my_list[239] + my_list[240] + my_list[241] + my_list[242] + my_list[243] + my_list[244] + my_list[245] + my_list[246] + my_list[247] + my_list[248] + my_list[249] + my_list[250] + my_list[251] + my_list[252] + my_list[253] + my_list[254] + my_list[255] + my_list[256] + my_list[257] + my_list[258] + my_list[259] + my_list[260] + my_list[261] + my_list[262] + my_list[263] + my_list[264] + my_list[265] + my_list[266] + my_list[267] + my_list[268] + my_list[269] + my_list[270] + my_list[271] + my_list[272] + my_list[273] + my_list[274] + my_list[275] + my_list[276] + my_list[277] + my_list[278] + my_list[279] + my_list[280] + my_list[281] + my_list[282] + my_list[283] + my_list[284] + my_list[285] + my_list[286] + my_list[287] + my_list[288] + my_list[289] + my_list[290] + my_list[291] + my_list[292] + my_list[293] + my_list[294] + my_list[295] + my_list[296] + my_list[297] + my_list[298] + my_list[299] + my_list[300] + my_list[301] + my_list[302] + my_list[303] + my_list[304] + my_list[305] + my_list[306] + my_list[307] + my_list[308] + my_list[309] + my_list[310] + my_list[311] + my_list[312] + my_list[313] + my_list[314] + my_list[315] + my_list[316] + my_list[317] + my_list[318] + my_list[319] + my_list[320] + my_list[321] + my_list[322] + my_list[323] + my_list[324] + my_list[325] + my_list[326] + my_list[327] + my_list[328] + my_list[329] + my_list[330] + my_list[331] + my_list[332] + my_list[333] + my_list[334] + my_list[335] + my_list[336] + my_list[337] + my_list[338] + my_list[339] + my_list[340] + my_list[341] + my_list[342] + my_list[343] + my_list[344] + my_list[345] + my_list[346] + my_list[347] + my_list[348] + my_list[349] + my_list[350] + my_list[351] + my_list[352] + my_list[353] + my_list[354] + my_list[355] + my_list[356] + my_list[357] + my_list[358] + my_list[359] + my_list[360] + my_list[361] + my_list[362] + my_list[363] + my_list[364] + my_list[365] + my_list[366] + my_list[367] + my_list[368] + my_list[369] + my_list[370] + my_list[371] + my_list[372] + my_list[373] + my_list[374] + my_list[375] + my_list[376] + my_list[377] + my_list[378] + my_list[379] + my_list[380] + my_list[381] + my_list[382] + my_list[383] + my_list[384] + my_list[385] + my_list[386] + my_list[387] + my_list[388] + my_list[389] + my_list[390] + my_list[391] + my_list[392] + my_list[393] + my_list[394] + my_list[395] + my_list[396] + my_list[397] + my_list[398] + my_list[399] + my_list[400] + my_list[401] + my_list[402] + my_list[403] + my_list[404] + my_list[405] + my_list[406] + my_list[407] + my_list[408] + my_list[409] + my_list[410] + my_list[411] + my_list[412] + my_list[413] + my_list[414] + my_list[415] + my_list[416] + my_list[417] + my_list[418] + my_list[419] + my_list[420] + my_list[421] + my_list[422] + my_list[423] + my_list[424] + my_list[425] + my_list[426] + my_list[427] + my_list[428] + my_list[429] + my_list[430] + my_list[431] + my_list[432] + my_list[433] + my_list[434] + my_list[435] + my_list[436] + my_list[437] + my_list[438] + my_list[439] + my_list[440] + my_list[441] + my_list[442] + my_list[443] + my_list[444] + my_list[445] + my_list[446] + my_list[447] + my_list[448] + my_list[449] + my_list[450] + my_list[451] + my_list[452] + my_list[453] + my_list[454] + my_list[455] + my_list[456] + my_list[457] + my_list[458] + my_list[459] + my_list[460] + my_list[461] + my_list[462] + my_list[463] + my_list[464] + my_list[465]
print(my_sum)



I would venture to guess that I successfully wrote a program that calculated the sum of all multiples of 3 or 5 below 1000, and that such program did not use any loops or recursion.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

36 minutes ago, cooldogz123 said:

Just use a C - syntax language, you can technically put the whole program on one line, as it is not whitespace sensitive, although it definitely hurts readability and debugging

That's no fun though.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, cooldogz123 said:

Just use a C - syntax language, you can technically put the whole program on one line, as it is not whitespace sensitive, although it definitely hurts readability and debugging

Every party needs a pooper that's why they invited you~

Technically, you're not wrong. But that also spoils the point of the challenge.

CPU - Ryzen 7 3700X | RAM - 64 GB DDR4 3200MHz | GPU - Nvidia GTX 1660 ti | MOBO -  MSI B550 Gaming Plus

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...
using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace pi**ingAround
{
    class Program
    {
        [DllImport("winmm.dll", EntryPoint = "mciSendString")]
        public static extern int mciSendStringA(string lpstrCommand, string lpstrReturnString,
                            int uReturnLength, int hwndCallback);
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("OPENED D - " + openDiskDrive("D"));
                }
                catch (Exception e)
                {
                    Console.WriteLine("EE" + e.Message);
                }

                Thread.Sleep(500);
                try
                {
                    Console.WriteLine("CLOSED D - "+closeDiskDrive("D"));
                }
                catch (Exception e)
                {
                   Console.WriteLine("EE" + e.Message);
                }
            }
        }
        private static string openDiskDrive(string driveLetter)
        {
            string returnString="";
            mciSendStringA("open " + driveLetter + ": type CDaudio alias drive" + driveLetter,
                 returnString, 0, 0);
            mciSendStringA("set drive" + driveLetter + " door open", returnString, 0, 0);
            return returnString;
        }
        private static string closeDiskDrive(string driveLetter)
        {
            string returnString = "";
            mciSendStringA("open " + driveLetter + ": type CDaudio alias drive" + driveLetter,
                 returnString, 0, 0);
            mciSendStringA("set drive" + driveLetter + " door closed", returnString, 0, 0);
            return returnString;
        }
    }
}

Opens and closes the disk drive of my colleagues PC, definitely useful...
He finds it very annoying, I find it very entertaining.

Even better, call it SVCHOST and watch their faces die when they kill their computer when they do taskkill /f /im svchost.exe :P

 

I hold an entertaining life....

Link to comment
Share on other sites

Link to post
Share on other sites

Also, I have this one to annoy people in the office...
I generally have the sleeps set to a few seconds...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace NotifLoop
{
    class Program
    {
        static void Main(string[] args)
        {
            
            while (true)
            {
                showNotification("I AM SPARTA", "U WOT MUSH");
                Thread.Sleep(30000);
            }
        }
        public static void showNotification(String title, String description)
        {
            new Thread(() =>
            {
                Thread.CurrentThread.IsBackground = true;
                var notification = new System.Windows.Forms.NotifyIcon()
                {
                    Visible = true,
                    Icon = System.Drawing.SystemIcons.Exclamation,
                    BalloonTipTitle = title,
                    BalloonTipText = description,
                };
                notification.ShowBalloonTip(5);
                Thread.Sleep(6000);
                notification.Dispose();
            }).Start();
        }
    }
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

This is my first post to the LTT forums, so - Hello World!

 

I did a small JS library back in 2013 called AutoCropJS. The point is that if you use an image with transparent background (in a web page) and you want to assign an event handler only when the user's mouse is over the visible pixels, you can use this library. It will prevent firing the event handlers chain if the action did not occur over a visible pixel. It is 109 lines with a ton of comments, so removing them will get it well below 100 lines ;) I have not tested it recently, so I hope it still works. https://github.com/raxbg/autocrop.js/blob/master/autocrop.js

Link to comment
Share on other sites

Link to post
Share on other sites

<?php
$url = "https://www.lectio.dk/lectio/518/SkemaNy.aspx?type=elev&elevid=IDHERE";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$output = curl_exec($ch);
curl_close($ch);
$regexpattern = '((\btitle[=]\")(.{1,50}\n)?((\d{1,2})\/(\d{1,2})-(\d{4})\s(\d{2}):(\d{2})\s\btil\s(\d{2}):(\d{2}))\n(\bHold:.*?\n.*?\n.*?)?\n)';
preg_match_all($regexpattern, $output, $regexresults);
echo '<pre>';print_r($regexresults);echo '</pre>';
?>

Gets infomation from Danish school sceduling website and outputs it in a usable format.

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...
import os
from ctypes import wintypes
import ctypes, win32ui, win32process, win32api, win32con
import time
from ctypes import *
from ctypes.wintypes import *

dwLocalPlayer = 0xAA38E4
dwEntityList = 0x4AC5E94
iCrossHairID = 0xAA70
iTeam = 0xF0
LifeState = 0x25B

HWND = win32ui.FindWindow(None, "Counter-Strike: Global Offensive").GetSafeHwnd()
PID = win32process.GetWindowThreadProcessId(HWND)[1]
PROCESS = win32api.OpenProcess(0x1F0FFF, 0, PID)

RPM2 = ctypes.WinDLL('kernel32',use_last_error=True).ReadProcessMemory
RPM2.argtypes = [wintypes.HANDLE,wintypes.LPCVOID,wintypes.LPVOID,ctypes.c_size_t,ctypes.POINTER(ctypes.c_size_t)]
RPM2.restype = wintypes.DWORD

def RPM(addr):
    buff = ctypes.create_string_buffer(32)
    bytes_read = ctypes.c_size_t()
    #print(bytes_read)
    RPM2(PROCESS.handle,addr,buff,32,ctypes.byref(bytes_read))
    return buff

def getModule(dllName):
    TH32CS_SNAPMODULE = (0x00000008)
    
    class MODULEENTRY32(Structure):
           _fields_ = [ ( 'dwSize' , DWORD ) , 
                    ( 'th32ModuleID' , DWORD ),
                    ( 'th32ProcessID' , DWORD ),
                    ( 'GlblcntUsage' , DWORD ),
                    ( 'ProccntUsage' , DWORD ) ,
                    ( 'modBaseAddr' , POINTER(BYTE)) ,
                    ( 'modBaseSize' , DWORD ) , 
                    ( 'hModule' , HMODULE ) ,
                    ( 'szModule' , c_char * 256 ),
                    ( 'szExePath' , c_char * 260 ) ]

    CreateToolhelp32Snapshot = ctypes.windll.kernel32.CreateToolhelp32Snapshot
    CloseHandle = ctypes.windll.kernel32.CloseHandle
    Module32First = ctypes.windll.kernel32.Module32First
    Module32Next = ctypes.windll.kernel32.Module32Next
    
    module = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PID)
    
    modentry = MODULEENTRY32()
    modentry.dwSize = sizeof(modentry)

    Module32First(module, byref(modentry))
    
    done = False
    while(done == False):
        print(modentry.szModule.decode("utf-8"))
        if modentry.szModule.decode("utf-8") == dllName:
            CloseHandle(module)
            done = True
            return modentry.modBaseAddr
        Module32Next(module, byref(modentry))
    return -1

dwClient = ctypes.c_void_p.from_buffer(getModule("client.dll")).value
print(dwClient)
#print(ctypes.get_last_error())
def getEntBase(plyNum):
    temp = RPM(dwClient + dwEntityList + (0x10*plyNum))
    retval = cast(temp, POINTER(c_int)).contents.value
    return retval

def getTeam(plyNum):
    temp = RPM(getEntBase(plyNum) + iTeam)
    retval = cast(temp, POINTER(c_int)).contents.value
    return retval

while(True):
    temp = RPM(dwClient + dwLocalPlayer)
    plyBase = cast(temp, POINTER(c_int)).contents.value
    temp2 = RPM(plyBase + iCrossHairID)
    plyNum = cast(temp2, POINTER(c_int)).contents.value - 1
    print(plyNum)
    temp3 = RPM(plyBase + iTeam)
    team = cast(temp3, POINTER(c_int)).contents.value
    if plyNum > 0 and plyNum < 64 and team != getTeam(plyNum):
        print("Click!")
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0)
        time.sleep(0.01)
        win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)
input()
 

 

Really shitty triggerbot for csgo cause I was bored and it's less than 100 lines.

Don't use this in game lol, just use -insecure option if you wanna test it with bots. Would not be surprised if it gets vac detected. Also cheating is bad.

 

btw I tried looking and couldn't find any rules against posting cheats but if there are sorry, I tried to find them at least? ;-;

 

Edited by jubjub
Link to comment
Share on other sites

Link to post
Share on other sites

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

// Void means the function doesn't return a value to the caller
// Int means the function returns a integer value to the caller


// adds number_1 and number_2
int add(int x, int y)
{
	cout << x + y << endl;
	return 0;
}

// subtracts number_1 and number_2
int subtract(int x, int y)
{
	cout << x - y << endl;
	return 0;
}

// divides number_1 and number_2
int divide(int x, int y)
{
	cout << x / y << endl;
	return 0;
}

// multiplys number_1 and number_2
int multiply(int x, int y)
{
	cout << x * y << endl;
	return 0;
}

int main()
{
	int number_1;
	int number_2;
	string operation;
	cout << "Enter a number: ";
	cin >> number_1;
	cout << "Enter another number: ";
	cin >> number_2;
	cout << "What operation do you want to do?: ";
	cin >> operation;

	// checks if the users typed in "add" and if so adds number_1 and number_2
	if (operation == "add")
	{
		add(number_1, number_2);
	}

	// checks if the users typed in "subtract" and if so subtracts number_1 and number_2
	else if (operation == "subtract")
	{
		subtract(number_1, number_2);
	}

	// checks if the users typed in "divide" and if so divides number_1 and number_2
	else if (operation == "divide")
	{
		divide(number_1, number_2);
	}

	// checks if the users typed in "multiply" and if so multiplys number_1 and number_2
	else if (operation == "multiply")
	{
		multiply(number_1, number_2);
	}

	// if the above checks fail this message will be displayed to the user
	else
	{
		cout << "Please input a valid opeartor!" << endl;

		// re-runs through the programm
		main();
	}


	cin.clear(); // reset any error flags
	cin.ignore(32767, '\n'); // ignore any characters in the input buffer until we find an enter character
	cin.get(); // get one more char from the user

	// returns 0
	return 0;

}

Just a simple calculator in C++. Since i'm new to the language it's not the best and can easily be broken but meh it's a start.

 

GitHub link: https://github.com/JackSewellDev/Calculator

Link to comment
Share on other sites

Link to post
Share on other sites

38 minutes ago, JackSewellDev said:

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

// Void means the function doesn't return a value to the caller
// Int means the function returns a integer value to the caller


// adds number_1 and number_2
int add(int x, int y)
{
	cout << x + y << endl;
	return 0;
}

// subtracts number_1 and number_2
int subtract(int x, int y)
{
	cout << x - y << endl;
	return 0;
}

// divides number_1 and number_2
int divide(int x, int y)
{
	cout << x / y << endl;
	return 0;
}

// multiplys number_1 and number_2
int multiply(int x, int y)
{
	cout << x * y << endl;
	return 0;
}

int main()
{
	int number_1;
	int number_2;
	string operation;
	cout << "Enter a number: ";
	cin >> number_1;
	cout << "Enter another number: ";
	cin >> number_2;
	cout << "What operation do you want to do?: ";
	cin >> operation;

	// checks if the users typed in "add" and if so adds number_1 and number_2
	if (operation == "add")
	{
		add(number_1, number_2);
	}

	// checks if the users typed in "subtract" and if so subtracts number_1 and number_2
	else if (operation == "subtract")
	{
		subtract(number_1, number_2);
	}

	// checks if the users typed in "divide" and if so divides number_1 and number_2
	else if (operation == "divide")
	{
		divide(number_1, number_2);
	}

	// checks if the users typed in "multiply" and if so multiplys number_1 and number_2
	else if (operation == "multiply")
	{
		multiply(number_1, number_2);
	}

	// if the above checks fail this message will be displayed to the user
	else
	{
		cout << "Please input a valid opeartor!" << endl;

		// re-runs through the programm
		main();
	}


	cin.clear(); // reset any error flags
	cin.ignore(32767, '\n'); // ignore any characters in the input buffer until we find an enter character
	cin.get(); // get one more char from the user

	// returns 0
	return 0;

}

Just a simple calculator in C++. Since i'm new to the language it's not the best and can easily be broken but meh it's a start.

 

GitHub link: https://github.com/JackSewellDev/Calculator

Could use 2 arrays instead of nested loops?

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, jubjub said:

Could use 2 arrays instead of nested loops?

Could you possibly provide a short example? I'm new to C++.

Link to comment
Share on other sites

Link to post
Share on other sites

56 minutes ago, JackSewellDev said:

Could you possibly provide a short example? I'm new to C++.

Have an array of function pointers and an array of your operations, loop through the operations array and check if it matches and if so access the function inside the function pointer array.

int add(int x, int y);

int main()
{
    int answer;
    int testx = 12;
    int testy = 23;
    char *operations[1] = { "addition" };
    int (*operationFunc[1])(int x, int y) = { add };
    
    for (int i = 0; i < 1; i++)
    {
        answer = (*operationFunc[i])(testx, testy);
    }

    return 0;
}

int add(int x, int y)
{
    return x + y;
}

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, YoungProgrammer said:

Website to count down to a date and time (in this case, Hannukah!).

Live: http://zachashton.me.uk/programming/hannukah


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Hannukah Countdown</title>

<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
 <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
 <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
 <![endif]-->
</head>
<body>
<div class="container">
<h2>It is</h2>
<div id="clockdiv">
    <div class="col-md-3">
        <h1 class="days"></h1>
        <h1 class="smalltext">Days</h1>
    </div>
    <div class="col-md-3">
        <h1 class="hours"></h1>
        <h1 class="smalltext">Hours</h1>
    </div>
    <div class="col-md-3">
        <h1 class="minutes"></h1>
        <h1 class="smalltext">Minutes</h1>
    </div>
    <div class="col-md-3">
        <h1 class="seconds"></h1>
        <h1 class="smalltext">Seconds</h1>
    </div>
</div>
<h2>till Hannukah!</h2>
<p>&lt;&gt; with &#x2764; by <a href="http://zachashton.me.uk">Zach</a></p>
</div>
<script>
    function getTimeRemaining(endtime) {
        var t = Date.parse(endtime) - Date.parse(new Date());
        var seconds = Math.floor((t / 1000) % 60);
        var minutes = Math.floor((t / 1000 / 60) % 60);
        var hours = Math.floor((t / (1000 * 60 * 60)) % 24);
        var days = Math.floor(t / (1000 * 60 * 60 * 24));
        return {
            'total': t,
            'days': days,
            'hours': hours,
            'minutes': minutes,
            'seconds': seconds
        };
    }

    function initializeClock(id, endtime) {
        var clock = document.getElementById(id);
        var daysSpan = clock.querySelector('.days');
        var hoursSpan = clock.querySelector('.hours');
        var minutesSpan = clock.querySelector('.minutes');
        var secondsSpan = clock.querySelector('.seconds');
        
        function updateClock() {
            var t = getTimeRemaining(endtime);
            
            daysSpan.innerHTML = t.days;
            hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
            minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
            secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
            
            if (t.total <= 0) {
                clearInterval(timeinterval);
            }
        }
        
        updateClock();
        var timeinterval = setInterval(updateClock, 1000);
    }
    var deadline = "2016-12-24T15:56";
    initializeClock('clockdiv', deadline);
</script>

<style>
    .container{
        text-align: center;
    }
</style>

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>

99/100 LINES! Beat that! (ok it does require bootstrap)

Looks great! I'm not much of a web developer but your code looks good.

Link to comment
Share on other sites

Link to post
Share on other sites

While writing a UNIX-ish OS (RazOS), I "needed" my own version of hexdump, so here it is

 

#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int read(FILE* file, int n, uint8_t* buf)
{
	uint8_t* tmp = buf;
	int c = 0, i = 0;

	do
	{
		c = fgetc(file);
		if (c != EOF)
		{
			*(tmp++) = c;
			i++;
		}
	} while (c != EOF && i < n);

	return i;
}

int main(int argc, char** argv)
{
	if (argc < 2)
	{
		printf("Usage: hexdump <file>\n");
		return -1;
	}

	FILE* file = fopen(argv[1], "r");
	uint8_t* buf = malloc(16);

	if (buf == NULL)
	{
		fprintf(stderr, "Memory error\n");
		return -1;
	}

	int n, i, j = 0;

	do
	{
		printf("%8.8x  ", j);
		n = read(file, 16, buf);

		for (i = 0; i < n; i++)
		{
			if (i > 0 && i % 8 == 0)
				printf(" ");

			printf("%2.2x ", *(buf+i));
		}

		if (n > 0)
		{
			if (i < 8)
				printf(" ");

			for (; i < 16; i++)
				printf("   ");
			printf(" |");
		}

		for (i = 0; i < n; i++)
		{
			if (isprint(*(buf+i)))
				printf("%c", *(buf+i));
			else
				printf(".");
		}

		if (n > 0)
			printf("|\n");

		j += n;
	} while (n > 0);

	printf("\n");

	return 0;
}

See the original: https://github.com/Razbit/razos/blob/master/tools/hexdump.c

 

Cheers!

Current rig: i7-5820K, R5E, 1070ti (windows), Radeon HD7850 (Mac), a bunch of SSDs and HDDs, running MacOS Mojave, Windows 10 + a bunch of debian servers on Proxmox KVM hypervisor

Laptop: MacBook Pro 13" 2017

 

Previous projects: Razmac G5, Server, zenbox HTPC

 

See my GitHub profile!

A coder/modder from Finland

Link to comment
Share on other sites

Link to post
Share on other sites

<?php 
date_default_timezone_set('Europe/London');
if (!isset($_REQUEST['i'])){die();}

$cachePath="./cache/";

//get image url
$full_url=$_REQUEST['i'];
//remove any characters that are crap.
$clean_url=$full_url;
$clean_url=str_replace("\/","_",$clean_url);
$clean_url=str_replace("/","_",$clean_url);
$clean_url=str_replace("?","_",$clean_url);
$clean_url=str_replace("&","_",$clean_url);
$clean_url=str_replace(":","_",$clean_url);
$clean_url=str_replace("___","_",$clean_url);
$clean_url=str_replace("-","_",$clean_url);
//$clean_url=str_replace("","",$clean_url);
//print $clean_url;

//debug::
//$clean_url="http://google.com";

$allimages=loadArray();
//print_r($allimages);

//check if exist already
$existsalready=false;
foreach ($allimages as $item) {
  if ($item['src']==$clean_url){
	//print "exists in array";
	if (new DateTime() > new DateTime($item['expire'])) {
	//	print "Expired";
		//delete image file.
	}else{
	//	print "not expired";
		$existsalready=true;
	}
  }
}
//if not exist, cache image.
if (!$existsalready){
	$name=$clean_url.".".getExtension($full_url);
	$newName=$cachePath.$name;
	file_put_contents($newName, file_get_contents($full_url));
	
	//generate cache expiration
	$dt = new DateTime();
	$dt->add(new DateInterval('PT1H'));
	$newDate=$dt->format('Y-m-d H:i:s');
	//print "Expire: ".$newDate;
	
	
	//add image to arrays...
	$allimages[]=[
		"src"=>$clean_url,
		"expire"=>$newDate,
	];
	saveArray($allimages);
}


//END: Load image.
$ext=getExtension($full_url);
header('Pragma: public');
header('Cache-Control: max-age=3600');
header('Expires: '. gmdate('D, d M Y H:i:s \G\M\T', time() + 3600));
header("Content-Type:image/".$ext); //passing the mimetype
if(is_file($newName) ||  is_file($newName = "./failcache.png"))
    readfile($newName);

//Set Headers, cache, expiration.
//display image


function saveArray($array){
	// serialize your input array (say $array)
	$serializedData = serialize($array);
	// save serialized data in a text file
	file_put_contents('imagecache.txt', $serializedData);
}
function loadArray(){
	//convert it back to array like:
	$recoveredData = file_get_contents('imagecache.txt');
	// unserializing to get actual array
	$recoveredArray = unserialize($recoveredData);
	return $recoveredArray;
}
function getExtension($url){
	$path_info = pathinfo($url);
	$str=$path_info['extension'];
	$extension= substr($str, 0, strrpos($str, '?'));
	return $extension;
}

Made a simple external image cache this morning.
94 lines but less without comments.

Link to comment
Share on other sites

Link to post
Share on other sites

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LearningCSharp
{

    class Program
    {

        // The main function
        static void Main(string[] args)
        {

            int total;

            Console.WriteLine("Please enter your first number: ");
            // Parses the str into a int and outputs it as number1
            int.TryParse(Console.ReadLine(), out int number1);

            Console.WriteLine("Please enter your second number: ");
            // Parses the str into a int and outputs it as number2
            int.TryParse(Console.ReadLine(), out int number2);

            total = Maths(number1, number2);

            Condition(total);

            Console.WriteLine($"The total of that sum is: {total}");

            switch(total)
            {
                case 768:
                    Console.WriteLine("Yay! The number was 768!");
                    break;
                default:
                    Console.WriteLine("Yay!");
                    break;
            }


            // Exit
            Console.WriteLine("Press the enter key to exit...");

            // Allows the user to see the content and press 'enter' to exit the application
            Console.ReadKey();
        }


        // Function for adding the two numbers
        static int Maths(int number1, int number2)
        {
            int total = number1 + number2;
            return total;
        }

        // Function for the conditional statements for total
        static void Condition(int total)
        {
            if (total < 100)
            {
                Console.WriteLine("Your total is smaller than 100!");
            }
            else if (total > 100)
            {
                Console.WriteLine("You total is bigger than 100!");
            }
            else
            {
                Console.WriteLine("It seems your number was exactly 100!");
            }
        }

    }

}

Learning C# and made this. Nothing huge just a basic console application using some stuff I've learnt.

Link to comment
Share on other sites

Link to post
Share on other sites

83 Lines. Python 2.7.13.

I needed a program that could copy 1 file into a bunch of directories which are all in the same directory. Couldn't find anything online so I made my own and wanted to share :)

Additionally, I wanted to make a program with a GUI. So here you go!! :D

For users who CBA to actually try it but want to see the sexy GUI:

2c7b45aacb87f046c722b12d7d0cf5ab.png

 


from Tkinter import *
from tkFileDialog import askopenfilename
from tkFileDialog import askdirectory
import os
import shutil

def fileName1():
    filename = askopenfilename()
    labelText1.set(filename)
    return

def copyFile(src, dest): # Copies file to dest
    try:
        shutil.copy(src, dest)
    # eg. src and dest are the same file
    except shutil.Error as e:
        print('Error 1: %s' % e)
    # eg. source or destination doesn't exist
    except IOError as e:
        print('Error 2: %s' % e.strerror)

def main():
    fileToCopy = labelText1.get()

    if os.path.dirname(fileToCopy):
        isFolderFound = True
        if e.get() != "":
            if os.path.exists(e.get()):
                isFolderFound = True
            else:
                isFolderFound = False
        else:
            isFolderFound = False

        if isFolderFound:
            directory = os.listdir(dirToCopyTo.get()) # Stores all files and folders
            for files in directory:
                # Files just returns folder name so add on to the DIR in the entry box
                files = dirToCopyTo.get()+"/"+files
                if os.path.isdir(files): # If dir (folder) then copyFile
                    copyFile(fileToCopy, files)
                    
            labelText2.set("Done")
        else:
            labelText2.set("Folder not found")
    else:
        labelText2.set("Pick a file")

app = Tk()
app.title("Copy file into all DIR")
app.geometry('370x100+550+340')

b1 = Button(app, text="Pick a File", command=fileName1, width=25)
b1.grid(row=0, column=0, pady=5, padx=5)

labelText1 = StringVar()
labelText1.set("<----")
e1 = Entry(app, textvariable=labelText1,width=25)
e1.grid(row=0, column=1, pady=5, padx=5)

def test():
    folderDir = askdirectory()
    dirToCopyTo.set(folderDir)

Button(app, text="Folder Directory", command=test, width=25).grid(row=1, column=0)

dirToCopyTo = StringVar()
dirToCopyTo.set("")

e = Entry(app, text=dirToCopyTo, width=25)
e.grid(row=1, column=1, pady=5, padx=5)

labelText2 = StringVar()
labelText2.set("-----")
label2 = Label(app, textvariable=labelText2)
label2.grid(row=2, column=1, pady=5, padx=5)


b3 = Button(app, text="Copy File", command=main, width=25)
b3.grid(row=2, column=0, pady=5, padx=5)

app.resizable(0,0)
app.mainloop()

There should be no bugs (No promises)

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

browsing through some old programming haunts and found this... had to share it. Wish I could claim credit for coming up with something so horrendously complicated myself, but I can't.

 

it's the most amazingly horrible 33 line program I ever read. And if you're confused what it does, well... it prints out "Hello world!".

It's almost something you have to check out yourself...

#include "stdio.h"
#define	e 3
#define	g (e/e)
#define	h ((g+e)/2)
#define	f (e-g-h)
#define	j (e*e-g)
#define k (j-h)
#define	l(x) tab2[x]/h
#define	m(n,a) ((n&(a))==(a))
 
long tab1[]={ 989L,5L,26L,0L,88319L,123L,0L,9367L };
int tab2[]={ 4,6,10,14,22,26,34,38,46,58,62,74,82,86 };
 
main(m1,s) char *s; {
    int a,b,c,d,o[k],n=(int)s;
    if(m1==1){ char b[2*j+f-g]; main(l(h+e)+h+e,b); printf(b); }
    else switch(m1-=h){
	case f:
	    a=(b=(c=(d=g)<<g)<<g)<<g;
	    return(m(n,a|c)|m(n,b)|m(n,a|d)|m(n,c|d));
	case h:
	    for(a=f;a<j;++a)if(tab1[a]&&!(tab1[a]%((long)l(n))))return(a);
	case g:
	    if(n<h)return(g);
	    if(n<j){n-=g;c='D';o[f]=h;o[g]=f;}
	    else{c='\r'-'\b';n-=j-g;o[f]=o[g]=g;}
	    if((b=n)>=e)for(b=g<<g;b<n;++b)o[b]=o[b-h]+o[b-g]+c;
	    return(o[b-g]%n+k-h);
	default:
	    if(m1-=e) main(m1-g+e+h,s+g); else *(s+g)=f;
	    for(*s=a=f;a<e;) *s=(*s<<e)|main(h+a++,(char *)m1);
	}
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 2 weeks later...

Technically only 5 lines, one is just reallllly long.

 

@echo off

	color 02

	:start

	echo According to all known laws of aviation, there is no way a bee should be able to fly. Its wings are too small to get its fat little body off the ground. The bee, of course, flies anyway because bees don't care what humans think is impossible. Yellow, black. Yellow, black. Yellow, black. Yellow, black. Ooh, black and yellow! Let's shake it up a little. Barry! Breakfast is ready! Coming! Hang on a second. Hello? Barry? Adam? Can you believe this is happening? I can't. I'll pick you up. Looking sharp. Use the stairs. Your father paid good money for those. Sorry. I'm excited. Here's the graduate. We're very proud of you, son. A perfect report card, all B's. Very proud. Ma! I got a thing going here. You got lint on your fuzz. Ow! That's me! Wave to us! We'll be in row 118,000. Bye! Barry, I told you, stop flying in the house! Hey, Adam. Hey, Barry. Is that fuzz gel? A little. Special day, graduation. Never thought I'd make it. Three days grade school, three days high school. Those were awkward. Three days college. I'm glad I took a day and hitchhiked around the hive. You did come back different. Hi, Barry. Artie, growing a mustache? Looks good. Hear about Frankie? Yeah. You going to the funeral? No, I'm not going. Everybody knows, sting someone, you die. Don't waste it on a squirrel. Such a hothead. I guess he could have just gotten out of the way. I love this incorporating an amusement park into our day. That's why we don't need vacations. Boy, quite a bit of pomp… under the circumstances. Well, Adam, today we are men. We are! Bee men. Amen! Hallelujah! Students, faculty, distinguished bees, please welcome Dean Buzzwell. Welcome, New Hive Oity graduating class of… …9:15. That concludes our ceremonies. And begins your career at Honex Industries! Will we pick our job today? I heard it's just orientation. Heads up! Here we go. Keep your hands and antennas inside the tram at all times. Wonder what it'll be like? A little scary. Welcome to Honex, a division of Honesco and a part of the Hexagon Group. This is it! Wow. Wow. We know that you, as a bee, have worked your whole life to get to the point where you can work for your whole life. Honey begins when our valiant Pollen Jocks bring the nectar to the hive. Our top secret formula is automatically color corrected, scent adjusted and bubble contoured into this soothing sweet syrup with its distinctive golden glow you know as… Honey! That girl was hot. She's my cousin! She is? Yes, we're all cousins. Right. You're right. At Honex, we constantly strive to improve every aspect of bee existence. These bees are stress testing a new helmet technology. What do you think he makes? Not enough. Here we have our latest advancement, the Krelman. What does that do? Catches that little strand of honey that hangs after you pour it. Saves us millions. Can anyone work on the Krelman? Of course. Most bee jobs are small ones. But bees know that every small job, if it's done well, means a lot. But choose carefully because you'll stay in the job you pick for the rest of your life. The same job the rest of your life? I didn't know that. What's the difference? You'll be happy to know that bees, as a species, haven't had one day off in 27 million years. So you'll just work us to death? We'll sure try. Wow! That blew my mind! “What's the difference?” How can you say that? One job forever? That's an insane choice to have to make. I'm relieved. Now we only have to make one decision in life. But, Adam, how could they never have told us that? Why would you question anything? We're bees. We're the most perfectly functioning society on Earth. You ever think maybe things work a little too well here? Like what? Give me one example. I don't know. But you know what I'm talking about. Please clear the gate. Royal Nectar Force on approach. Wait a second. Check it out. Hey, those are Pollen Jocks! Wow. I've never seen them this close. They know what it's like outside the hive. Yeah, but some don't come back. Hey, Jocks! Hi, Jocks! You guys did great! You're monsters! You're sky freaks! I love it! I love it! I wonder where they were. I don't know. Their day's not planned. Outside the hive, flying who knows where, doing who knows what. You can't just decide to be a Pollen Jock. You have to be bred for that. Right. Look. That's more pollen than you and I will see in a lifetime. It's just a status symbol. Bees make too much of it. Perhaps. Unless you're wearing it and the ladies see you wearing it. Those ladies? Aren't they our cousins too? Distant. Distant. Look at these two. Couple of Hive Harrys. Let's have fun with them. It must be dangerous being a Pollen Jock. Yeah. Once a bear pinned me against a mushroom! He had a paw on my throat, and with the other, he was slapping me! Oh, my! I never thought I'd knock him out. What were you doing during this? Trying to alert the authorities. I can autograph that. A little gusty out there today, wasn't it, comrades? Yeah. Gusty. We're hitting a sunflower patch six miles from here tomorrow. Six miles, huh? Barry! A puddle jump for us, but maybe you're not up for it. Maybe I am. You are not! We're going 0900 at J Gate. What do you think, buzzy boy? Are you bee enough? I might be. It all depends on what 0900 means. Hey, Honex! Dad, you surprised me. You decide what you're interested in? Well, there's a lot of choices. But you only get one. Do you ever get bored doing the same job every day? Son, let me tell you about stirring. You grab that stick, and you just move it around, and you stir it around. You get yourself into a rhythm. It's a beautiful thing. You know, Dad, the more I think about it, maybe the honey field just isn't right for me. You were thinking of what, making balloon animals? That's a bad job for a guy with a stinger. Janet, your son's not sure he wants to go into honey! Barry, you are so funny sometimes. I'm not trying to be funny. You're not funny! You're going into honey. Our son, the stirrer! You're gonna be a stirrer? No one's listening to me! Wait till you see the sticks I have. I could say anything right now. I'm gonna get an ant tattoo! Let's open some honey and celebrate! Maybe I'll pierce my thorax. Shave my antennae. Shack up with a grasshopper. Get a gold tooth and call everybody “dawg”! I'm so proud. We're starting work today! Today's the day. Come on! All the good jobs will be gone. Yeah, right. Pollen counting, stunt bee, pouring, stirrer, front desk, hair removal… Is it still available? Hang on. Two left! One of them's yours! Congratulations! Step to the side. What'd you get? Picking crud out. Stellar! Wow! Couple of newbies? Yes, sir! Our first day! We are ready! Make your choice. You want to go first? No, you go. Oh, my. What's available? Restroom attendant's open, not for the reason you think. Any chance of getting the Krelman? Sure, you're on. I'm sorry, the Krelman just closed out. Wax monkey's always open. The Krelman opened up again. What happened? A bee died. Makes an opening. See? He's dead. Another dead one. Deady. Deadified. Two more dead. Dead from the neck up. Dead from the neck down. That's life! Oh, this is so hard! Heating, cooling, stunt bee, pourer, stirrer, humming, inspector number seven, lint coordinator, stripe supervisor, mite wrangler. Barry, what do you think I should… Barry? Barry! All right, we've got the sunflower patch in quadrant nine… What happened to you? Where are you? I'm going out. Out? Out where? Out there. Oh, no! I have to, before I go to work for the rest of my life. You're gonna die! You're crazy! Hello? Another call coming in. If anyone's feeling brave, there's a Korean deli on 83rd that gets their roses today. Hey, guys. Look at that. Isn't that the kid we saw yesterday? Hold it, son, flight deck's restricted. It's OK, Lou. We're gonna take him up. Really? Feeling lucky, are you? Sign here, here. Just initial that. Thank you. OK. You got a rain advisory today, and as you all know, bees cannot fly in rain. So be careful. As always, watch your brooms, hockey sticks, dogs, birds, bears and bats. Also, I got a couple of reports of root beer being poured on us. Murphy's in a home because of it, babbling like a cicada! That's awful. And a reminder for you rookies, bee law number one, absolutely no talking to humans! All right, launch positions! Buzz, buzz, buzz, buzz! Buzz, buzz, buzz, buzz! Buzz, buzz, buzz, buzz! Black and yellow! Hello! You ready for this, hot shot? Yeah. Yeah, bring it on. Wind, check. Antennae, check. Nectar pack, check. Wings, check. Stinger, check. Scared out of my shorts, check. OK, ladies, let's move it out! Pound those petunias, you striped stem suckers! All of you, drain those flowers! Wow! I'm out! I can't believe I'm out! So blue. I feel so fast and free! Box kite! Wow! Flowers! This is Blue Leader. We have roses visual. Bring it around 30 degrees and hold. Roses! 30 degrees, roger. Bringing it around. Stand to the side, kid. It's got a bit of a kick. That is one nectar collector! Ever see pollination up close? No, sir. I pick up some pollen here, sprinkle it over here. Maybe a dash over there, a pinch on that one. See that? It's a little bit of magic. That's amazing. Why do we do that? That's pollen power. More pollen, more flowers, more nectar, more honey for us. Cool. I'm picking up a lot of bright yellow. Could be daisies. Don't we need those? Copy that visual. Wait. One of these flowers seems to be on the move. Say again? You're reporting a moving flower? Affirmative. That was on the line! This is the coolest. What is it? I don't know, but I'm loving this color. It smells good. Not like a flower, but I like it. Yeah, fuzzy. Chemical y. Careful, guys. It's a little grabby. My sweet lord of bees! Candy brain, get off there! Problem! Guys! This could be bad. Affirmative. Very close. Gonna hurt. Mama's little boy. You are way out of position, rookie! Coming in at you like a missile! Help me! I don't think these are flowers. Should we tell him? I think he knows. What is this?! Match point! You can start packing up, honey, because you're about to eat it! Yowser! Gross. There's a bee in the car! Do something! I'm driving! Hi, bee. He's back here! He's going to sting me! Nobody move. If you don't move, he won't sting you. Freeze! He blinked! Spray him, Granny! What are you doing?! Wow… the tension level out here is unbelievable. I gotta get home. Can't fly in rain. Can't fly in rain. Can't fly in rain. Mayday! Mayday! Bee going down! Ken, could you close the window please? Ken, could you close the window please? Check out my new resume. I made it into a fold out brochure. You see? Folds out. Oh, no. More humans. I don't need this. What was that? Maybe this time. This time. This time. This time! This time! This… Drapes! That is diabolical. It's fantastic. It's got all my special skills, even my top ten favorite movies. What's number one? Star Wars? Nah, I don't go for that… …kind of stuff. No wonder we shouldn't talk to them. They're out of their minds. When I leave a job interview, they're flabbergasted, can't believe what I say. There's the sun. Maybe that's a way out. I don't remember the sun having a big 75 on it. I predicted global warming. I could feel it getting hotter. At first I thought it was just me. Wait! Stop! Bee! Stand back. These are winter boots. Wait! Don't kill him! You know I'm allergic to them! This thing could kill me! Why does his life have less value than yours? Why does his life have any less value than mine? Is that your statement? I'm just saying all life has value. You don't know what he's capable of feeling. My brochure! There you go, little guy. I'm not scared of him. It's an allergic thing. Put that on your resume brochure. My whole face could puff up. Make it one of your special skills. Knocking someone out is also a special skill. Right. Bye, Vanessa. Thanks. Vanessa, next week? Yogurt night? Sure, Ken. You know, whatever. You could put carob chips on there. Bye. Supposed to be less calories. Bye. I gotta say something. She saved my life. I gotta say something. All right, here it goes. Nah. What would I say? I could really get in trouble. It's a bee law. You're not supposed to talk to a human. I can't believe I'm doing this. I've got to. Oh, I can't do it. Come on! No. Yes. No. Do it. I can't. How should I start it? “You like jazz?” No, that's no good. Here she comes! Speak, you fool! Hi! I'm sorry. You're talking. Yes, I know. You're talking! I'm so sorry. No, it's OK. It's fine. I know I'm dreaming. But I don't recall going to bed. Well, I'm sure this is very disconcerting. This is a bit of a surprise to me. I mean, you're a bee! I am. And I'm not supposed to be doing this, but they were all trying to kill me. And if it wasn't for you… I had to thank you. It's just how I was raised. That was a little weird. I'm talking with a bee. Yeah. I'm talking to a bee. And the bee is talking to me! I just want to say I'm grateful. I'll leave now. Wait! How did you learn to do that? What? The talking thing. Same way you did, I guess. “Mama, Dada, honey.” You pick it up. That's very funny. Yeah. Bees are funny. If we didn't laugh, we'd cry with what we have to deal with. Anyway… Can I… …get you something? Like what? I don't know. I mean… I don't know. Coffee? I don't want to put you out. It's no trouble. It takes two minutes. It's just coffee. I hate to impose. Don't be ridiculous! Actually, I would love a cup. Hey, you want rum cake? I shouldn't. Have some. No, I can't. Come on! I'm trying to lose a couple micrograms. Where? These stripes don't help. You look great! I don't know if you know anything about fashion. Are you all right? No. He's making the tie in the cab as they're flying up Madison. He finally gets there. He runs up the steps into the church. The wedding is on. And he says, “Watermelon? I thought you said Guatemalan. Why would I marry a watermelon?” Is that a bee joke? That's the kind of stuff we do. Yeah, different. So, what are you gonna do, Barry? About work? I don't know. I want to do my part for the hive, but I can't do it the way they want. I know how you feel. You do? Sure. My parents wanted me to be a lawyer or a doctor, but I wanted to be a florist. Really? My only interest is flowers. Our new queen was just elected with that same campaign slogan. Anyway, if you look… There's my hive right there. See it? You're in Sheep Meadow! Yes! I'm right off the Turtle Pond! No way! I know that area. I lost a toe ring there once. Why do girls put rings on their toes? Why not? It's like putting a hat on your knee. Maybe I'll try that. You all right, ma'am? Oh, yeah. Fine. Just having two cups of coffee! Anyway, this has been great. Thanks for the coffee. Yeah, it's no trouble. Sorry I couldn't finish it. If I did, I'd be up the rest of my life. Are you…? Can I take a piece of this with me? Sure! Here, have a crumb. Thanks! Yeah. All right. Well, then… I guess I'll see you around. Or not. OK, Barry. And thank you so much again… for before. Oh, that? That was nothing. Well, not nothing, but… Anyway… This can't possibly work. He's all set to go. We may as well try it. OK, Dave, pull the chute. Sounds amazing. It was amazing! It was the scariest, happiest moment of my life. Humans! I can't believe you were with humans! Giant, scary humans! What were they like? Huge and crazy. They talk crazy. They eat crazy giant things. They drive crazy. Do they try and kill you, like on TV? Some of them. But some of them don't. How'd you get back? Poodle. You did it, and I'm glad. You saw whatever you wanted to see. You had your “experience.” Now you can pick out your job and be normal. Well… Well? Well, I met someone. You did? Was she Bee ish? A wasp?! Your parents will kill you! No, no, no, not a wasp. Spider? I'm not attracted to spiders. I know it's the hottest thing, with the eight legs and all. I can't get by that face. So who is she? She's… human. No, no. That's a bee law. You wouldn't break a bee law. Her name's Vanessa. Oh, boy. She's so nice. And she's a florist! Oh, no! You're dating a human florist! We're not dating. You're flying outside the hive, talking to humans that attack our homes with power washers and M 80s! One eighth a stick of dynamite! She saved my life! And she understands me. This is over! Eat this. This is not over! What was that? They call it a crumb. It was so stingin' stripey! And that's not what they eat. That's what falls off what they eat! You know what a Cinnabon is? No. It's bread and cinnamon and frosting. They heat it up… Sit down! …really hot! Listen to me! We are not them! We're us. There's us and there's them! Yes, but who can deny the heart that is yearning? There's no yearning. Stop yearning. Listen to me! You have got to start thinking bee, my friend. Thinking bee! Thinking bee. Thinking bee. Thinking bee! Thinking bee! Thinking bee! Thinking bee! There he is. He's in the pool. You know what your problem is, Barry? I gotta start thinking bee? How much longer will this go on? It's been three days! Why aren't you working? I've got a lot of big life decisions to think about. What life? You have no life! You have no job. You're barely a bee! Would it kill you to make a little honey? Barry, come out. Your father's talking to you. Martin, would you talk to him? Barry, I'm talking to you! You coming? Got everything? All set! Go ahead. I'll catch up. Don't be too long. Watch this! Vanessa! We're still here. I told you not to yell at him. He doesn't respond to yelling! Then why yell at me? Because you don't listen! I'm not listening to this. Sorry, I've gotta go. Where are you going? I'm meeting a friend. A girl? Is this why you can't decide? Bye. I just hope she's Bee ish. They have a huge parade of flowers every year in Pasadena? To be in the Tournament of Roses, that's every florist's dream! Up on a float, surrounded by flowers, crowds cheering. A tournament. Do the roses compete in athletic events? No. All right, I've got one. How come you don't fly everywhere? It's exhausting. Why don't you run everywhere? It's faster. Yeah, OK, I see, I see. All right, your turn. TiVo. You can just freeze live TV? That's insane! You don't have that? We have Hivo, but it's a disease. It's a horrible, horrible disease. Oh, my. Dumb bees! You must want to sting all those jerks. We try not to sting. It's usually fatal for us. So you have to watch your temper. Very carefully. You kick a wall, take a walk, write an angry letter and throw it out. Work through it like any emotion: Anger, jealousy, lust. Oh, my goodness! Are you OK? Yeah. What is wrong with you?! It's a bug. He's not bothering anybody. Get out of here, you creep! What was that? A Pic ‘N’ Save circular? Yeah, it was. How did you know? It felt like about 10 pages. Seventy five is pretty much our limit. You've really got that down to a science. I lost a cousin to Italian Vogue. I'll bet. What in the name of Mighty Hercules is this? How did this get here? Cute Bee, Golden Blossom, Ray Liotta Private Select? Is he that actor? I never heard of him. Why is this here? For people. We eat it. You don't have enough food of your own? Well, yes. How do you get it? Bees make it. I know who makes it! And it's hard to make it! There's heating, cooling, stirring. You need a whole Krelman thing! It's organic. It's our ganic! It's just honey, Barry. Just what?! Bees don't know about this! This is stealing! A lot of stealing! You've taken our homes, schools, hospitals! This is all we have! And it's on sale?! I'm getting to the bottom of this. I'm getting to the bottom of all of this! Hey, Hector. You almost done? Almost. He is here. I sense it. Well, I guess I'll go home now and just leave this nice honey out, with no one around. You're busted, box boy! I knew I heard something. So you can talk! I can talk. And now you'll start talking! Where you getting the sweet stuff? Who's your supplier? I don't understand. I thought we were friends. The last thing we want to do is upset bees! You're too late! It's ours now! You, sir, have crossed the wrong sword! You, sir, will be lunch for my iguana, Ignacio! Where is the honey coming from? Tell me where! Honey Farms! It comes from Honey Farms! Crazy person! What horrible thing has happened here? These faces, they never knew what hit them. And now they're on the road to nowhere! Just keep still. What? You're not dead? Do I look dead? They will wipe anything that moves. Where you headed? To Honey Farms. I am onto something huge here. I'm going to Alaska. Moose blood, crazy stuff. Blows your head off! I'm going to Tacoma. And you? He really is dead. All right. Uh oh! What is that?! Oh, no! A wiper! Triple blade! Triple blade? Jump on! It's your only chance, bee! Why does everything have to be so doggone clean?! How much do you people need to see?! Open your eyes! Stick your head out the window! From NPR News in Washington, I'm Carl Kasell. But don't kill no more bugs! Bee! Moose blood guy!! You hear something? Like what? Like tiny screaming. Turn off the radio. Whassup, bee boy? Hey, Blood. Just a row of honey jars, as far as the eye could see. Wow! I assume wherever this truck goes is where they're getting it. I mean, that honey's ours. Bees hang tight. We're all jammed in. It's a close community. Not us, man. We on our own. Every mosquito on his own. What if you get in trouble? You a mosquito, you in trouble. Nobody likes us. They just smack. See a mosquito, smack, smack! At least you're out in the world. You must meet girls. Mosquito girls try to trade up, get with a moth, dragonfly. Mosquito girl don't want no mosquito. You got to be kidding me! Mooseblood's about to leave the building! So long, bee! Hey, guys! Mooseblood! I knew I'd catch y'all down here. Did you bring your crazy straw? We throw it in jars, slap a label on it, and it's pretty much pure profit. What is this place? A bee's got a brain the size of a pinhead. They are pinheads! Pinhead. Check out the new smoker. Oh, sweet. That's the one you want. The Thomas 3000! Smoker? Ninety puffs a minute, semi automatic. Twice the nicotine, all the tar. A couple breaths of this knocks them right out. They make the honey, and we make the money. “They make the honey, and we make the money”? Oh, my! What's going on? Are you OK? Yeah. It doesn't last too long. Do you know you're in a fake hive with fake walls? Our queen was moved here. We had no choice. This is your queen? That's a man in women's clothes! That's a drag queen! What is this? Oh, no! There's hundreds of them! Bee honey. Our honey is being brazenly stolen on a massive scale! This is worse than anything bears have done! I intend to do something. Oh, Barry, stop. Who told you humans are taking our honey? That's a rumor. Do these look like rumors? That's a conspiracy theory. These are obviously doctored photos. How did you get mixed up in this? He's been talking to humans. What? Talking to humans?! He has a human girlfriend. And they make out! Make out? Barry! We do not. You wish you could. Whose side are you on? The bees! I dated a cricket once in San Antonio. Those crazy legs kept me up all night. Barry, this is what you want to do with your life? I want to do it for all our lives. Nobody works harder than bees! Dad, I remember you coming home so overworked your hands were still stirring. You couldn't stop. I remember that. What right do they have to our honey? We live on two cups a year. They put it in lip balm for no reason whatsoever! Even if it's true, what can one bee do? Sting them where it really hurts. In the face! The eye! That would hurt. No. Up the nose? That's a killer. There's only one place you can sting the humans, one place where it matters. Hive at Five, the hive's only full hour action news source. No more bee beards! With Bob Bumble at the anchor desk. Weather with Storm Stinger. Sports with Buzz Larvi. And Jeanette Chung. Good evening. I'm Bob Bumble. And I'm Jeanette Chung. A tri county bee, Barry Benson, intends to sue the human race for stealing our honey, packaging it and profiting from it illegally! Tomorrow night on Bee Larry King, we'll have three former queens here in our studio, discussing their new book, Classy Ladies, out this week on Hexagon. Tonight we're talking to Barry Benson. Did you ever think, “I'm a kid from the hive. I can't do this”? Bees have never been afraid to change the world. What about Bee Columbus? Bee Gandhi? Bejesus? Where I'm from, we'd never sue humans. We were thinking of stickball or candy stores. How old are you? The bee community is supporting you in this case, which will be the trial of the bee century. You know, they have a Larry King in the human world too. It's a common name. Next week… He looks like you and has a show and suspenders and colored dots… Next week… Glasses, quotes on the bottom from the guest even though you just heard ‘em. Bear Week next week! They’re scary, hairy and here live. Always leans forward, pointy shoulders, squinty eyes, very Jewish. In tennis, you attack at the point of weakness! It was my grandmother, Ken. She's 81. Honey, her backhand's a joke! I'm not gonna take advantage of that? Quiet, please. Actual work going on here. Is that that same bee? Yes, it is! I'm helping him sue the human race. Hello. Hello, bee. This is Ken. Yeah, I remember you. Timberland, size ten and a half. Vibram sole, I believe. Why does he talk again? Listen, you better go 'cause we're really busy working. But it's our yogurt night! Bye bye. Why is yogurt night so difficult?! You poor thing. You two have been at this for hours! Yes, and Adam here has been a huge help. Frosting… How many sugars? Just one. I try not to use the competition. So why are you helping me? Bees have good qualities. And it takes my mind off the shop. Instead of flowers, people are giving balloon bouquets now. Those are great, if you're three. And artificial flowers. Oh, those just get me psychotic! Yeah, me too. Bent stingers, pointless pollination. Bees must hate those fake things! Nothing worse than a daffodil that's had work done. Maybe this could make up for it a little bit. This lawsuit's a pretty big deal. I guess. You sure you want to go through with it? Am I sure? When I'm done with the humans, they won't be able to say, “Honey, I'm home,” without paying a royalty! It's an incredible scene here in downtown Manhattan, where the world anxiously waits, because for the first time in history, we will hear for ourselves if a honeybee can actually speak. What have we gotten into here, Barry? It's pretty big, isn't it? I can't believe how many humans don't work during the day. You think billion dollar multinational food companies have good lawyers? Everybody needs to stay behind the barricade. What's the matter? I don't know, I just got a chill. Well, if it isn't the bee team. You boys work on this? All rise! The Honorable Judge Bumbleton presiding. All right. Case number 4475, Superior Court of New York, Barry Bee Benson v. the Honey Industry is now in session. Mr. Montgomery, you're representing the five food companies collectively? A privilege. Mr. Benson… you're representing all the bees of the world? I'm kidding. Yes, Your Honor, we're ready to proceed. Mr. Montgomery, your opening statement, please. Ladies and gentlemen of the jury, my grandmother was a simple woman. Born on a farm, she believed it was man's divine right to benefit from the bounty of nature God put before us. If we lived in the topsy turvy world Mr. Benson imagines, just think of what would it mean. I would have to negotiate with the silkworm for the elastic in my britches! Talking bee! How do we know this isn't some sort of holographic motion picture capture Hollywood wizardry? They could be using laser beams! Robotics! Ventriloquism! Cloning! For all we know, he could be on steroids! Mr. Benson? Ladies and gentlemen, there's no trickery here. I'm just an ordinary bee. Honey's pretty important to me. It's important to all bees. We invented it! We make it. And we protect it with our lives. Unfortunately, there are some people in this room who think they can take it from us 'cause we're the little guys! I'm hoping that, after this is all over, you'll see how, by taking our honey, you not only take everything we have but everything we are! I wish he'd dress like that all the time. So nice! Call your first witness. So, Mr. Klauss Vanderhayden of Honey Farms, big company you have. I suppose so. I see you also own Honeyburton and Honron! Yes, they provide beekeepers for our farms. Beekeeper. I find that to be a very disturbing term. I don't imagine you employ any bee free ers, do you? No. I couldn't hear you. No. No. Because you don't free bees. You keep bees. Not only that, it seems you thought a bear would be an appropriate image for a jar of honey. They're very lovable creatures. Yogi Bear, Fozzie Bear, Build A Bear. You mean like this? Bears kill bees! How'd you like his head crashing through your living room?! Biting into your couch! Spitting out your throw pillows! OK, that's enough. Take him away. So, Mr. Sting, thank you for being here. Your name intrigues me. Where have I heard it before? I was with a band called The Police. But you've never been a police officer, have you? No, I haven't. No, you haven't. And so here we have yet another example of bee culture casually stolen by a human for nothing more than a prance about stage name. Oh, please. Have you ever been stung, Mr. Sting? Because I'm feeling a little stung, Sting. Or should I say… Mr. Gordon M. Sumner! That's not his real name?! You idiots! Mr. Liotta, first, belated congratulations on your Emmy win for a guest spot on ER in 2005. Thank you. Thank you. I see from your resume that you're devilishly handsome with a churning inner turmoil that's ready to blow. I enjoy what I do. Is that a crime? Not yet it isn't. But is this what it's come to for you? Exploiting tiny, helpless bees so you don't have to rehearse your part and learn your lines, sir? Watch it, Benson! I could blow right now! This isn't a goodfella. This is a badfella! Why doesn't someone just step on this creep, and we can all go home?! Order in this court! You're all thinking it! Order! Order, I say! Say it! Mr. Liotta, please sit down! I think it was awfully nice of that bear to pitch in like that. I think the jury's on our side. Are we doing everything right, legally? I'm a florist. Right. Well, here's to a great team. To a great team! Well, hello. Ken! Hello. I didn't think you were coming. No, I was just late. I tried to call, but… the battery. I didn't want all this to go to waste, so I called Barry. Luckily, he was free. Oh, that was lucky. There's a little left. I could heat it up. Yeah, heat it up, sure, whatever. So I hear you're quite a tennis player. I'm not much for the game myself. The ball's a little grabby. That's where I usually sit. Right… there. Ken, Barry was looking at your resume, and he agreed with me that eating with chopsticks isn't really a special skill. You think I don't see what you're doing? I know how hard it is to find the right job. We have that in common. Do we? Bees have 100 percent employment, but we do jobs like taking the crud out. That's just what I was thinking about doing. Ken, I let Barry borrow your razor for his fuzz. I hope that was all right. I'm going to drain the old stinger. Yeah, you do that. Look at that. You know, I've just about had it with your little mind games. What's that? Italian Vogue. Mamma mia, that's a lot of pages. A lot of ads. Remember what Van said, why is your life more valuable than mine? Funny, I just can't seem to recall that! I think something stinks in here! I love the smell of flowers. How do you like the smell of flames?! Not as much. Water bug! Not taking sides! Ken, I'm wearing a Chapstick hat! This is pathetic! I've got issues! Well, well, well, a royal flush! You're bluffing. Am I? Surf's up, dude! Poo water! That bowl is gnarly. Except for those dirty yellow rings! Kenneth! What are you doing?! You know, I don't even like honey! I don't eat it! We need to talk! He's just a little bee! And he happens to be the nicest bee I've met in a long time! Long time? What are you talking about?! Are there other bugs in your life? No, but there are other things bugging me in life. And you're one of them! Fine! Talking bees, no yogurt night… My nerves are fried from riding on this emotional roller coaster! Goodbye, Ken. And for your information, I prefer sugar free, artificial sweeteners made by man! I'm sorry about all that. I know it's got an aftertaste! I like it! I always felt there was some kind of barrier between Ken and me. I couldn't overcome it. Oh, well. Are you OK for the trial? I believe Mr. Montgomery is about out of ideas. We would like to call Mr. Barry Benson Bee to the stand. Good idea! You can really see why he's considered one of the best lawyers… Yeah. Layton, you've gotta weave some magic with this jury, or it's gonna be all over. Don't worry. The only thing I have to do to turn this jury around is to remind them of what they don't like about bees. You got the tweezers? Are you allergic? Only to losing, son. Only to losing. Mr. Benson Bee, I'll ask you what I think we'd all like to know. What exactly is your relationship to that woman? We're friends. Good friends? Yes. How good? Do you live together? Wait a minute… Are you her little… …bedbug? I've seen a bee documentary or two. From what I understand, doesn't your queen give birth to all the bee children? Yeah, but… So those aren't your real parents! Oh, Barry… Yes, they are! Hold me back! You're an illegitimate bee, aren't you, Benson? He's denouncing bees! Don't y'all date your cousins? Objection! I'm going to pincushion this guy! Adam, don't! It's what he wants! Oh, I'm hit!! Oh, lordy, I am hit! Order! Order! The venom! The venom is coursing through my veins! I have been felled by a winged beast of destruction! You see? You can't treat them like equals! They're striped savages! Stinging's the only thing they know! It's their way! Adam, stay with me. I can't feel my legs. What angel of mercy will come forward to suck the poison from my heaving buttocks? I will have order in this court. Order! Order, please! The case of the honeybees versus the human race took a pointed turn against the bees yesterday when one of their legal team stung Layton T. Montgomery. Hey, buddy. Hey. Is there much pain? Yeah. I… I blew the whole case, didn't I? It doesn't matter. What matters is you're alive. You could have died. I'd be better off dead. Look at me. They got it from the cafeteria downstairs, in a tuna sandwich. Look, there's a little celery still on it. What was it like to sting someone? I can't explain it. It was all… All adrenaline and then… and then ecstasy! All right. You think it was all a trap? Of course. I'm sorry. I flew us right into this. What were we thinking? Look at us. We're just a couple of bugs in this world. What will the humans do to us if they win? I don't know. I hear they put the roaches in motels. That doesn't sound so bad. Adam, they check in, but they don't check out! Oh, my. Could you get a nurse to close that window? Why? The smoke. Bees don't smoke. Right. Bees don't smoke. Bees don't smoke! But some bees are smoking. That's it! That's our case! It is? It's not over? Get dressed. I've gotta go somewhere. Get back to the court and stall. Stall any way you can. And assuming you've done step correctly, you're ready for the tub. Mr. Flayman. Yes? Yes, Your Honor! Where is the rest of your team? Well, Your Honor, it's interesting. Bees are trained to fly haphazardly, and as a result, we don't make very good time. I actually heard a funny story about… Your Honor, haven't these ridiculous bugs taken up enough of this court's valuable time? How much longer will we allow these absurd shenanigans to go on? They have presented no compelling evidence to support their charges against my clients, who run legitimate businesses. I move for a complete dismissal of this entire case! Mr. Flayman, I'm afraid I'm going to have to consider Mr. Montgomery's motion. But you can't! We have a terrific case. Where is your proof? Where is the evidence? Show me the smoking gun! Hold it, Your Honor! You want a smoking gun? Here is your smoking gun. What is that? It's a bee smoker! What, this? This harmless little contraption? This couldn't hurt a fly, let alone a bee. Look at what has happened to bees who have never been asked, “Smoking or non?” Is this what nature intended for us? To be forcibly addicted to smoke machines and man-made wooden slat work camps? Living out our lives as honey slaves to the white man? What are we gonna do? He's playing the species card. Ladies and gentlemen, please, free these bees! Free the bees! Free the bees! Free the bees! Free the bees! Free the bees! The court finds in favor of the bees! Vanessa, we won! I knew you could do it! High five! Sorry. I'm OK! You know what this means? All the honey will finally belong to the bees. Now we won't have to work so hard all the time. This is an unholy perversion of the balance of nature, Benson. You'll regret this. Barry, how much honey is out there? All right. One at a time. Barry, who are you wearing? My sweater is Ralph Lauren, and I have no pants. What if Montgomery's right? What do you mean? We've been living the bee way a long time, 27 million years. Congratulations on your victory. What will you demand as a settlement? First, we'll demand a complete shutdown of all bee work camps. Then we want back the honey that was ours to begin with, every last drop. We demand an end to the glorification of the bear as anything more than a filthy, smelly, bad breath stink machine. We're all aware of what they do in the woods. Wait for my signal. Take him out. He'll have nauseous for a few hours, then he'll be fine. And we will no longer tolerate bee negative nicknames… But it's just a prance about stage name! …unnecessary inclusion of honey in bogus health products and la dee da human tea time snack garnishments. Can't breathe. Bring it in, boys! Hold it right there! Good. Tap it. Mr. Buzzwell, we just passed three cups, and there's gallons more coming! I think we need to shut down! Shut down? We've never shut down. Shut down honey production! Stop making honey! Turn your key, sir! What do we do now? Cannonball! We're shutting honey production! Mission abort. Aborting pollination and nectar detail. Returning to base. Adam, you wouldn't believe how much honey was out there. Oh, yeah? What's going on? Where is everybody? Are they out celebrating? They're home. They don't know what to do. Laying out, sleeping in. I heard your Uncle Oarl was on his way to San Antonio with a cricket. At least we got our honey back. Sometimes I think, so what if humans liked our honey? Who wouldn't? It's the greatest thing in the world! I was excited to be part of making it. This was my new desk. This was my new job. I wanted to do it really well. And now… Now I can't. I don't understand why they're not happy. I thought their lives would be better! They're doing nothing. It's amazing. Honey really changes people. You don't have any idea what's going on, do you? What did you want to show me? This. What happened here? That is not the half of it. Oh, no. Oh, my. They're all wilting. Doesn't look very good, does it? No. And whose fault do you think that is? You know, I'm gonna guess bees. Bees? Specifically, me. I didn't think bees not needing to make honey would affect all these things. It's notjust flowers. Fruits, vegetables, they all need bees. That's our whole SAT test right there. Take away produce, that affects the entire animal kingdom. And then, of course… The human species? So if there's no more pollination, it could all just go south here, couldn't it? I know this is also partly my fault. How about a suicide pact? How do we do it? I'll sting you, you step on me. That just kills you twice. Right, right. Listen, Barry… sorry, but I gotta get going. I had to open my mouth and talk. Vanessa? Vanessa? Why are you leaving? Where are you going? To the final Tournament of Roses parade in Pasadena. They've moved it to this weekend because all the flowers are dying. It's the last chance I'll ever have to see it. Vanessa, I just wanna say I'm sorry. I never meant it to turn out like this. I know. Me neither. Tournament of Roses. Roses can't do sports. Wait a minute. Roses. Roses? Roses! Vanessa! Roses?! Barry? Roses are flowers! Yes, they are. Flowers, bees, pollen! I know. That's why this is the last parade. Maybe not. Could you ask him to slow down? Could you slow down? Barry! OK, I made a huge mistake. This is a total disaster, all my fault. Yes, it kind of is. I've ruined the planet. I wanted to help you with the flower shop. I've made it worse. Actually, it's completely closed down. I thought maybe you were remodeling. But I have another idea, and it's greater than my previous ideas combined. I don't want to hear it! All right, they have the roses, the roses have the pollen. I know every bee, plant and flower bud in this park. All we gotta do is get what they've got back here with what we've got. Bees. Park. Pollen! Flowers. Repollination! Across the nation! Tournament of Roses, Pasadena, California. They've got nothing but flowers, floats and cotton candy. Security will be tight. I have an idea. Vanessa Bloome, FTD. Official floral business. It's real. Sorry, ma'am. Nice brooch. Thank you. It was a gift. Once inside, we just pick the right float. How about The Princess and the Pea? I could be the princess, and you could be the pea! Yes, I got it. Where should I sit? What are you? I believe I'm the pea. The pea? It goes under the mattresses. Not in this fairy tale, sweetheart. I'm getting the marshal. You do that! This whole parade is a fiasco! Let's see what this baby'll do. Hey, what are you doing?! Then all we do is blend in with traffic… …without arousing suspicion. Once at the airport, there's no stopping us. Stop! Security. You and your insect pack your float? Yes. Has it been in your possession the entire time? Would you remove your shoes? Remove your stinger. It's part of me. I know. Just having some fun. Enjoy your flight. Then if we're lucky, we'll have just enough pollen to do the job. Can you believe how lucky we are? We have just enough pollen to do the job! I think this is gonna work. It's got to work. Attention, passengers, this is Captain Scott. We have a bit of bad weather in New York. It looks like we'll experience a couple hours delay. Barry, these are cut flowers with no water. They'll never make it. I gotta get up there and talk to them. Be careful. Can I get help with the Sky Mall magazine? I'd like to order the talking inflatable nose and ear hair trimmer. Captain, I'm in a real situation. What'd you say, Hal? Nothing. Bee! Don't freak out! My entire species… What are you doing? Wait a minute! I'm an attorney! Who's an attorney? Don't move. Oh, Barry. Good afternoon, passengers. This is your captain. Would a Miss Vanessa Bloome in 24B please report to the cockpit? And please hurry! What happened here? There was a DustBuster, a toupee, a life raft exploded. One's bald, one's in a boat, they're both unconscious! Is that another bee joke? No! No one's flying the plane! This is JFK control tower, Flight 356. What's your status? This is Vanessa Bloome. I'm a florist from New York. Where's the pilot? He's unconscious, and so is the copilot. Not good. Does anyone onboard have flight experience? As a matter of fact, there is. Who's that? Barry Benson. From the honey trial?! Oh, great. Vanessa, this is nothing more than a big metal bee. It's got giant wings, huge engines. I can't fly a plane. Why not? Isn't John Travolta a pilot? Yes. How hard could it be? Wait, Barry! We're headed into some lightning. This is Bob Bumble. We have some late breaking news from JFK Airport, where a suspenseful scene is developing. Barry Benson, fresh from his legal victory… That's Barry! …is attempting to land a plane, loaded with people, flowers and an incapacitated flight crew. Flowers?! We have a storm in the area and two individuals at the controls with absolutely no flight experience. Just a minute. There's a bee on that plane. I'm quite familiar with Mr. Benson and his no account compadres. They've done enough damage. But isn't he your only hope? Technically, a bee shouldn't be able to fly at all. Their wings are too small… Haven't we heard this a million times? “The surface area of the wings and body mass make no sense.” Get this on the air! Got it. Stand by. We're going live. The way we work may be a mystery to you. Making honey takes a lot of bees doing a lot of small jobs. But let me tell you about a small job. If you do it well, it makes a big difference. More than we realized. To us, to everyone. That's why I want to get bees back to working together. That's the bee way! We're not made of Jell O. We get behind a fellow. Black and yellow! Hello! Left, right, down, hover. Hover? Forget hover. This isn't so hard. Beep beep! Beep beep! Barry, what happened?! Wait, I think we were on autopilot the whole time. That may have been helping me. And now we're not! So it turns out I cannot fly a plane. All of you, let's get behind this fellow! Move it out! Move out! Our only chance is if I do what I'd do, you copy me with the wings of the plane! Don't have to yell. I'm not yelling! We're in a lot of trouble. It's very hard to concentrate with that panicky tone in your voice! It's not a tone. I'm panicking! I can't do this! Vanessa, pull yourself together. You have to snap out of it! You snap out of it. You snap out of it. You snap out of it! You snap out of it! You snap out of it! You snap out of it! You snap out of it! You snap out of it! Hold it! Why? Come on, it's my turn. How is the plane flying? I don't know. Hello? Benson, got any flowers for a happy occasion in there? The Pollen Jocks! They do get behind a fellow. Black and yellow. Hello. All right, let's drop this tin can on the blacktop. Where? I can't see anything. Can you? No, nothing. It's all cloudy. Come on. You got to think bee, Barry. Thinking bee. Thinking bee. Thinking bee! Thinking bee! Thinking bee! Wait a minute. I think I'm feeling something. What? I don't know. It's strong, pulling me. Like a 27 million year old instinct. Bring the nose down. Thinking bee! Thinking bee! Thinking bee! What in the world is on the tarmac? Get some lights on that! Thinking bee! Thinking bee! Thinking bee! Vanessa, aim for the flower. OK. Out the engines. We're going in on bee power. Ready, boys? Affirmative! Good. Good. Easy, now. That's it. Land on that flower! Ready? Full reverse! Spin it around! Not that flower! The other one! Which one? That flower. I'm aiming at the flower! That's a fat guy in a flowered shirt. I mean the giant pulsating flower made of millions of bees! Pull forward. Nose down. Tail up. Rotate around it. This is insane, Barry! This's the only way I know how to fly. Am I koo koo kachoo, or is this plane flying in an insect like pattern? Get your nose in there. Don't be afraid. Smell it. Full reverse! Just drop it. Be a part of it. Aim for the center! Now drop it in! Drop it in, woman! Come on, already. Barry, we did it! You taught me how to fly! Yes. No high five! Right. Barry, it worked! Did you see the giant flower? What giant flower? Where? Of course I saw the flower! That was genius! Thank you. But we're not done yet. Listen, everyone! This runway is covered with the last pollen from the last flowers available anywhere on Earth. That means this is our last chance. We're the only ones who make honey, pollinate flowers and dress like this. If we're gonna survive as a species, this is our moment! What do you say? Are we going to be bees, or just Museum of Natural History keychains? We're bees! Keychain! Then follow me! Except Keychain. Hold on, Barry. Here. You've earned this. Yeah! I'm a Pollen Jock! And it's a perfect fit. All I gotta do are the sleeves. Oh, yeah. That's our Barry. Mom! The bees are back! If anybody needs to make a call, now's the time. I got a feeling we'll be working late tonight! Here's your change. Have a great afternoon! Can I help who's next? Would you like some honey with that? It is bee approved. Don't forget these. Milk, cream, cheese, it's all me. And I don't see a nickel! Sometimes I just feel like a piece of meat! I had no idea. Barry, I'm sorry. Have you got a moment? Would you excuse me? My mosquito associate will help you. Sorry I'm late. He's a lawyer too? I was already a blood sucking parasite. All I needed was a briefcase. Have a great afternoon! Barry, I just got this huge tulip order, and I can't get them anywhere. No problem, Vannie. Just leave it to me. You're a lifesaver, Barry. Can I help who's next? All right, scramble, jocks! It's time to fly. Thank you, Barry! That bee is living my life! Let it go, Kenny. When will this nightmare end?! Let it all go. Beautiful day to fly. Sure is. Between you and me, I was dying to get out of that office. You have got to start thinking bee, my friend. Thinking bee! Me? Hold it. Let's just stop for a second. Hold it. I'm sorry. I'm sorry, everyone. Can we stop here? I'm not making a major life decision during a production number! All right. Take ten, everybody. Wrap it up, guys. I had virtually no rehearsal for that. 

	goto start[ /code]
Link to comment
Share on other sites

Link to post
Share on other sites

This is a java program which allows the user to set a shutdown timer. 150 lines.

The shutdown timer can be canceled restarted and has a progress bar so you can see how much time is left till shutdown.

Made this a while ago but thought I would share it.

If you like it I have a bunch of other stuff I can share.

 

I apologize for any rude comments or variable names. I don't always keep things polite in my code : /

 

**I quickly reread the code and it could be reduced quite a bit. A few lines by replacing the mouse listener with a mouse adapter. Some black lines. Could fit under 100.**

public class MainWindow
{

	private JFrame frame;
	private boolean on = false;
	private JProgressBar progressBar;
	private Color NeonGreen = new Color(0,255,128);
	private Color NeonBlue = new Color(0,200,255);
	private Color NeonRed = new Color(255,102,102);
	private Color Fade = new Color(45,45,45);
	private long start;
	private long end;
	private long cur;
	private long estimate;
	private float calc;
	private Timer timer = new Timer(1000, new ActionListener()
	{	@Override
		public void actionPerformed(ActionEvent e)
		{
			cur = System.currentTimeMillis() - start;
			calc = (float) cur / (float) estimate * 100;
			progressBar.setValue((int) calc);
		}});

	public static void main(String[] args)
	{
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{try{MainWindow window = new MainWindow();window.frame.setVisible(true);}
			catch(Exception e){e.printStackTrace();}}
		});
	}
	public MainWindow(){initialize();}
	private void initialize()
	{
		
		frame = new JFrame();
		frame.setBounds(100, 100, 259, 121);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setResizable(false);
		frame.setTitle("hPower");
		frame.setAlwaysOnTop(true);
		frame.getContentPane().setBackground(Color.black);
		frame.getContentPane().setLayout(null);
		
		JLabel lblCountdown = new JLabel("Countdown");
		lblCountdown.setBounds(10, 11, 121, 14);
		lblCountdown.setForeground(NeonGreen);
		frame.getContentPane().add(lblCountdown);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setBounds(79, 8, 164, 20);
		comboBox.setForeground(NeonGreen);
		comboBox.setBackground(Fade);
		comboBox.setFocusable(false);
		frame.getContentPane().add(comboBox);
		
		JButton btnStartStop = new JButton("Start");
		btnStartStop.setBounds(79, 58, 103, 23);
		btnStartStop.setBorder(null);
		btnStartStop.setFocusable(false);
		btnStartStop.setForeground(NeonGreen);
		btnStartStop.setBackground(Color.black);
		btnStartStop.setBorder(new LineBorder(NeonGreen));
		frame.getContentPane().add(btnStartStop);
		btnStartStop.addMouseListener(new MouseListener()
		{
			@Override
			public void mouseExited(MouseEvent arg0)
			{Hover(arg0, arg0.getComponent().getForeground(), arg0.getComponent().getBackground());}
			@Override
			public void mouseEntered(MouseEvent arg0)
			{Hover(arg0, arg0.getComponent().getForeground(), arg0.getComponent().getBackground());}
			@Override
			public void mouseClicked(MouseEvent arg0){}
			@Override
			public void mousePressed(MouseEvent arg0){}
			@Override
			public void mouseReleased(MouseEvent arg0){}
		});
		
		//Filling combo
		comboBox.addItem("5 minutes");
		comboBox.addItem("15 minutes");
		comboBox.addItem("30 minutes");
		comboBox.addItem("45 minutes");
		comboBox.addItem("1 hour");
		comboBox.addItem("1 hour 30 minutes");
		comboBox.addItem("2 hours");
		
		progressBar = new JProgressBar();
		progressBar.setBounds(10, 36, 233, 14);
		progressBar.setBackground(Fade);
		progressBar.setForeground(NeonGreen);
		progressBar.setFocusable(false);
		progressBar.setBorder(new LineBorder(NeonGreen));
		frame.getContentPane().add(progressBar);
		
		btnStartStop.addActionListener(new ActionListener()
		{
			
			@SuppressWarnings("unused")
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				if(on)
				{
					try
					{
						Runtime runtime = Runtime.getRuntime();
						Process proc = runtime.exec("shutdown -a");
						btnStartStop.setBackground(NeonGreen);
						btnStartStop.setBorder(new LineBorder(NeonGreen));
						btnStartStop.setText("Start");
						on = false;
						timer.stop();
					}catch(IOException e){}
				}else
				{
					try
					{
						Runtime runtime = Runtime.getRuntime();
						Process proc = runtime.exec("shutdown -s -t "+timer(comboBox.getSelectedIndex()));
						btnStartStop.setText("Stop");
						btnStartStop.setBackground(NeonRed);
						btnStartStop.setBorder(new LineBorder(NeonRed));
						start = System.currentTimeMillis();
						end = System.currentTimeMillis() + timer(comboBox.getSelectedIndex()) * 1000;
						estimate = end - start;
						on = true;
						timer.start();
					}catch(IOException e){}
				}
			}
		});
	}
	private int timer(int index)
	{
		String time;
		if(index == 0){time = "300";}else if(index == 1)
		{time = "900";}else if(index == 2){time = "1800";}else if(index == 3)
		{time = "2700";}else if(index == 4){time = "3600";}else if(index == 5)
		{time = "5400";}else{time = "7200";}
		return Integer.parseInt(time);
	}
	private void Hover(MouseEvent arg, Color color1, Color color2)
	{arg.getComponent().setBackground(color1);
	arg.getComponent().setForeground(color2);}
}

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×