This is not meant to be a gripe thread. This is merely to serve as a conduit between myself and getting a better understanding for what I'm confused about. I remember back when I was using eclipse in my high school CS class that using java was extremely easy and you could easily write some simple lines of code to make a simple box. With a little more ease, it wasn't hard to code some buttons that did some functions. What I'm curious is why if its so easy for java to do it, how come c++ can't? And if it can and I'm not aware, why is it that no one I talk to can help me with it? I feel as though if I could have my question answered, I could give back rather than have to gripe and gripe about this.
Java is a high level language with an overhead while C/C++ is not. In itself, C++ is just a language without knowledge of what is a keyboard, monitor, modem, mouse, etc. This means that C++ in itself is unable to display graphics, read keystrokes, etc. Libraries must be used for this, but you must remember that since C++ is used for different OS's then there are diffierent libraries.
So one library comes along and someone is not happy with it and creates a new one, usually building on the previous one. The end result is a new library that is (usually) easier to use and with less code. But did you really shorten the code necessary to achieve the task? Not really. You are merely reusing existing code.
Well, that is in essence what Java does. Java provides a runtime library (per OS) that does many things in the background for you so you can write simple programs. They are hardly magical, though, as the end result is pretty much the same: At some point someone must have coded Java itself, and most likely they did it in C or C++.
How come there isn't a simple library that I can use that lets me just specify dimensions for a box? Or a line of code that allows me to create a button that, if clicked, will call a function somewhere in my program, and then print back out to the box?
Maybe there is. I don't know every single library out there. But you must remember that if you are looking for one, you must take into account the operating system and whether it is a console program or a windowed program.
For example, wxWidgets simplifies Windows programming for windowed programs quite a bit but I am unsure if that's what you are looking for as you haven't mentioned your requirements.
sounds like qt is a library perfect for you. it has a very nice framework, and it is pretty powerfull. it is a framework that allows you to make gui programs.
CreateWindow(L"button", // We're making a button
L"Cancel", // This is what the button will say.
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, // styles
50, 100, // X and Y position (in pixels)
150, 30, // Width and Height
hWnd, // Handle to the parent window
(HMENU) ID_BUTTON1, // enum'd identifier for this button, it's used to identify the source of the message when your parent window gets the code.
NULL, NULL // some optional stuff here.
);
Nope, cross platform API's are generally easier to use than their platform specific counterparts. The reasons for going platform specific usually boil down to performance/memory limitations in one way or another.
Like I said, this is a small very uncomplicated application that I want to make. Its basically a timer. You hit a button, it calls my timer function, creates a timer, then calls another function that displays the time remaining. The only "complicated" part in it I might see is right now, as a console app, you can only create one timer at a time.
You can create as many as you want, there's no fundamental difference between a console application and a GUI application. Besides, you just said you only need one.
Actually, the way its set up, no I can't create more than one. Once its created a single timer, the console locks up and starts cout'ing the time remaining for that timer. And unless I break out of that by some keystroke, I can't make more than one timer.
A GUI is not magically able to do things the console cannot. If you appear to be able to do something with a GUI that the console simply cannot do, that's because the GUI library is hiding things from you. Things like threads.
#include <iostream>
#include "Timer.h"
usingnamespace std;
Timer::Timer() // default constructor
{
hour = 0;
min = 0;
sec = 0;
}
Timer::Timer(int h, int m, int s) // specialized constructor
{
hour = h;
min = m;
sec = s;
}
void Timer::CurrTimePrint() // Prints out time.
{
cout << hour << ":";
cout << setw(2) << setfill( '0' ) << min;
cout << "." << setw(2) << setfill( '0' ) << sec;
cout << endl;
}
void Timer::GetTime() // Gets the time and stores it in an object
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
hour = timeinfo -> tm_hour;
min = timeinfo -> tm_min;
sec = timeinfo -> tm_sec;
}
void Timer::SpawnTimer(Timer &timer) // Passes by reference a timer and gets its data needed
{
//////////////////////////////////////////////////////////////////////////////////////
if((timer.TimerName == "ob") || (timer.TimerName == "OB"))
{
timer.TimerName = "Blue Buff: Ours";
//cout << "STARTED BLUE BUFF: OURS" << endl;
timer.min = 4;
timer.sec = 58;
//grab the amount of time for a blue buff
//make sure it saves that spawn is OUR and print that where needed
//send the time to the add method
}
//////////////////////////////////////////////////////////////////////////////////////
elseif((timer.TimerName == "tb") || (timer.TimerName == "TB"))
{
timer.TimerName = "Blue Buff: Theirs";
//cout << "STARTED BLUE BUFF: THEIRS" << endl;
timer.min = 4;
timer.sec = 58;
//grab the amount of time for a blue buff
//make sure it saves that spawn is THEIRS and print that where needed
//send the time to the add method
}
//////////////////////////////////////////////////////////////////////////////////////
elseif((timer.TimerName == "or") || (timer.TimerName == "OR"))
{
timer.TimerName = "Red Buff: Ours";
//cout << "STARTED RED BUFF: OURS" << endl;
timer.min = 4;
timer.sec = 58;
//grab the amount of time for a red buff
//make sure it saves that spawn is OUR and print that where needed
//send the time to the add method
}
//////////////////////////////////////////////////////////////////////////////////////
elseif((timer.TimerName == "tr") || (timer.TimerName == "TR"))
{
timer.TimerName = "Red Buff: Theirs";
//cout << "STARTED RED BUFF: THEIRS" << endl;
timer.min = 4;
timer.sec = 58;
//grab the amount of time for a red buff
//make sure it saves that spawn is THEIRS and print that where needed
//send the time to the add method
}
//////////////////////////////////////////////////////////////////////////////////////
elseif((timer.TimerName == "drag") || (timer.TimerName == "DRAG"))
{
timer.TimerName = "Dragon";
//cout << "STARTED DRAGON" << endl;
timer.min = 5;
timer.sec = 58;
//grab the amount of time for dragon
}
//////////////////////////////////////////////////////////////////////////////////////
elseif((timer.TimerName == "baron") || (timer.TimerName == "BARON"))
{
timer.TimerName = "Baron";
//cout << "STARTED BARON" << endl;
timer.min = 6;
timer.sec = 58;
//grab the amount of time for baron
}
//////////////////////////////////////////////////////////////////////////////////////
elseif((timer.TimerName == "test"))// TEST CASE
{
//cout << "test" << endl;
timer.min = 1;
timer.sec = 15;
}
}
// timer method gets current time
// timer method that checks for what spawn timer needed
// timer method adds spawn time to current time
// timer method compares current time with spawn time
// timer method that prints to screen timer expires
// timer method that prints out remaining time (i.e 1 minute left, 30 seconds out)
#include <iostream>
#include "TimerManager.h"
usingnamespace std;
TimerManager::TimerManager()
{
//Forgot to do something with this.
}
bool TimerManager::timeCompare(Timer current, Timer goalTime, int &c1, int &c2, int &tS)
{
///////////////////////////////////////////////////////////////
// CHECKS THE TIMES TO SEE IF TIMER HAS EXPIRED
current.GetTime();
int minuteLeft, secondLeft; // temp variables to hold time differences
secondLeft = goalTime.sec - current.sec;
minuteLeft = goalTime.min - current.min;
if((minuteLeft == 0) && (secondLeft == 0))
returntrue;
///////////////////////////////////////////////////////////////
// USED TO KEEP TIME CONSTRAINTS PRINTED NORMAL (I.E prevents printing 1:60)
if(secondLeft < 0) // if secondLeft is less than zero. converts to fix time holes
{
if(minuteLeft > 0)
{
int tempSec = 60;
minuteLeft--;
secondLeft = tempSec + secondLeft;
}
elseif(minuteLeft > 1)
{
secondLeft = 60 + secondLeft;
}
}
elseif(secondLeft > 60) // if secondLeft is greater than 60. converts to fix time holes
{
minuteLeft++;
secondLeft = secondLeft - 60;
}
elseif(secondLeft == 60) // if secondLeft is 60, prevents
{
secondLeft = 0;
minuteLeft++;
}
/////////////////////////////////////////////////////////////
// REPEAT PRINT CHECK / ALSO CONVERTS SINGLE DIGIT SECONDS TO :0x, x = second
if((tS != secondLeft))
{
if((secondLeft < 10) && (secondLeft >= 0)) // ex. 0:1 into 0:00
{
cout << minuteLeft << ":0" << secondLeft << endl;
}
else
cout << minuteLeft << ":" << secondLeft << endl;
}
////////////////////////////////////////////////////////////////////////////////////
// WARNING TREES
////////////////////////////////////////////////////////////////////////////////////
// ONE MINUTE WARNING TREE
if((minuteLeft == 1) && (secondLeft == 0))
{
if(c1 != 1)
{
cout << "ONE MINUTE WARNING" << endl;
c1++;
}
}
///////////////////////////////////////////////////////////////
// THIRTY SECOND WARNING TREE
if((minuteLeft == 0) && (secondLeft == 30))
{
if(c2 != 1)
{
cout << "30 SECOND WARNING" << endl;
c2++;
}
}
///////////////////////////////////////////////////////////////
// ZERO TIME CHECK
if((minuteLeft == 0) && (secondLeft == 0))
{
returntrue;
}
///////////////////////////////////////////////////////////////
tS = secondLeft; // REFERENCE TO MAIN
returnfalse;
///////////////////////////////////////////////////////////////
}
// This would work by having it check/update all initialized timers and check if any of them
// are currently close to any pertinent print times(i.e. 1 minute out, 30 seconds out). This would
// then take them and see about storing some sort of bool or possibly returning the string associated
// with the given timer object.