Juan Mendez-DePaz allegedly told the worker he had two guns in his vest when he went to the fast-food restaurant in Riverside early Sunday.
The worker closed the window and called 911.
State troopers responded and confronted Mendez-DePaz in the parking lot. He was still wearing the cowboy hat and black vest described in the McDonald's worker's 911 call, police said.
The suspect displayed a large knife on his hip, and was taken into custody after a brief struggle, state police said.
Mendez-DePaz was charged with criminal possession of a weapon and first-degree robbery.
Information on an attorney for him wasn't immediately available.