Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Sunday, January 20, 2013

C++: dot vs arrow

What's the difference?

Basically,
a->b 
is
(a*).b

Dot (.)
  1. can't be overloaded (I'll figure out what that means later)
  2. used to access a member within a derefenced pointer (so, it's pretty much outdated when it comes to pointers)
Arrow (->)
  1. CAN be overloaded (yay)
  2. used to access a member within a pointer


searches:
c++ dot versus arrow
cpp dot arrow

Friday, January 4, 2013

Java: smoother rendering in swing

It took me 3 projects but I finally realized why my Java swing animations look choppy and stuttery. I was using swing's paint() method.


If this is as simple as a JFrame (swing) application gets:
public class Main extends JFrame
{
    public Main()
    {
        setSize(640, 480);
    }

    @Override
    public void paint(Graphics g) 
    {
        g.setColor(new Color( (int) System.currentTimeMillis() % 255 ));
        g.fillRect(0, 0, 640, 480);
    }
    
    public static void main(String args[]) 
    {
        Main launcher = new Main();
        launcher.setVisible(true);
        while(true)
        {
            launcher.repaint();
        }
    }
}

This will do the same thing but more consistently and smoothly:
public class Main extends JFrame
{
    public Main()
    {
        setSize(640, 480);
    }
    
    public static void main(String args[]) 
    {
        Main launcher = new Main();
        launcher.setVisible(true);
        while(true)
        {
            Graphics g = launcher.getGraphics();
            g.setColor(new Color( (int) System.currentTimeMillis() % 255 ));
            g.fillRect(0, 0, 640, 480);
        }
    }
}

Swing's repaint() system does extra things every so often, and it visibly trips up animation, especially motion animation.

Don't override swing's paint() method. Manually grab the canvas and draw to it when you want to

searches:
java animation stuttering
java smooth animation
java swing laggy
smooth rendering in swing

Sunday, December 16, 2012

Visual Studio: using namespace System error

Visual Studio doesn't automatically set itself up to use forms.


If you make a new project and add a form, follow these additional steps.

1) Open your solution explorer panel (Ctrl+Alt+L). Right click your project and click properties


2) In the dialog that opens, navigate to Configuration Properties > General. Find the field that says "Common Language Runtime Support". Answer with "yes, I'd love some 'Common Language Runtime Support (/clr)' ".


And then smack it because it should've known that already

searches:
using namespace system name must be a namespace name
using namespace system error
namespace system does not exist

Saturday, December 15, 2012

C++: change application icon

You'd think it'd be more obvious how to give your executable a unique icon. Every application has one. Why should yours be stuck with this:

Visual Studio has a built-in way to set your application's icon. It's just not immediately obvious.

1) In Visual Studio, open the Resource View panel (View > Other Windows > Resource View) or (Ctrl+Shift+E).


2) Right click your project (e.g. Project1), click Add > Resource. If it gives you an error for whatever reason, just try again.


3) In the dialog that pops up, click "Icon" and click "Import..."


4) Choose the icon you want. Make sure you make icons visible because ico's are the only filetype that'll work.


5) Visual Studio automatically takes that icon and tells your executable that's the way it's gonna look. So go ahead and build your project (Build > Build Solution) or (Ctrl+Shift+B). If you go to your project's debug folder (or release folder, depending on which mode you're in) (My Documents/Visual Studio {version}/Projects/{project name}/Debug/) you'll notice your application has a more acceptable appearance.


searches:
c++ set executable icon
visual studio set application icon

Thursday, December 13, 2012

C++: hide icon from taskbar

C++ has some convoluted way.

Visual Studio has a straightforward way, if you're using a form.

1) Look at your Solution Explorer and open your form's header file


2) Click your form's design space, just to make sure it's in focus


3) In the properties panel, scroll down to "ShowInTaskbar." Set that to "False"

searches:
c++ remove icon from taskbar
c++ hide icon from  taskbar