These codes is a part of a whole .java file,but it can reach the goal you want