events - Java GUI BorderLayout application 4 buttons Left, right, up and down each move location -
i have been breaking head days on project have in java beginner class gui borderlayout jbutton , hope 1 here can me out understand or shed light. task create borderlayout window 4 button left right , down each button moves window/ borderlayout 20 pixel left or right or or down. have created code buttons not know how make buttons move , above must not allow window move out/ disappear desktop. please patient me totally fresh student. here code far:
import java.awt.*; import javax.swing.*; public class windowborder extends jframe { private static final long serialversionuid = 1l; private int x, y; //the coordinates moving in screen public windowborder (string titel){ super (titel); //create buttons , layout , add buttons jbutton right = new jbutton ("right"); jbutton left = new jbutton ("left"); jbutton = new jbutton ("up"); jbutton down = new jbutton ("down"); //jbutton center = new jbutton ("default"); hide middle button setlayout (new borderlayout (75,75)); add(borderlayout.east,right); add(borderlayout.west,left); add(borderlayout.north,up); add(borderlayout.south,down); //add(borderlayout.center,default); hide middle button //i must create inner class constructors task project school class windowborderinner implements actionlistener { @override public void actionperformed (actionevent e){ if(e.getactioncommand().equals("right")) //this part lost :( } } //configuration size , location of border layout setsize (400,400); setlocationbyplatform (true); setvisible(true); setdefaultcloseoperation(jframe.exit_on_close); } public static void main(string [] arg){ //the test method new windowborder("move window"); } }
i'm on mobile can't(won't) type out code, copied out of thread
jframe.setlocation(jframe.getx() + 5, jframe.gety()); you can manually set location of jframe in way when action listener called.
Comments
Post a Comment