Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 11th, 2013, 02:12 AM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
Post Help Opening New Class

please help me how to open
the new window class that i create in this program
and i want to change the keystroke("M") that i use in (ALT+F1) key please help me thanks


Code:
public class MainClass {

  public static void main(final String args[]) {
    final JFrame frame = new JFrame("Frame Key");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Action actionListener = new AbstractAction() {
      public void actionPerformed(ActionEvent actionEvent) {
      new window();   // open new class file
      }
    };
    
    JPanel content = (JPanel) frame.getContentPane();
    KeyStroke stroke = KeyStroke.getKeyStroke("M");
    //KeyStroke stroke = KeyStroke.getKeyStroke("VK_ALT");    
    InputMap inputMap = content.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(stroke, "OPEN");
    content.getActionMap().put("OPEN", actionListener);
   
    frame.setSize(300, 300);
    frame.setVisible(true);
  }
}



Reply With Quote
  #2  
Old January 11th, 2013, 01:51 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,955 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 53 m 34 sec
Reputation Power: 345
Try this:
KeyStroke.getKeyStroke(KeyEvent.VK_F1, ActionEvent.ALT_MASK );

Reply With Quote
  #3  
Old January 24th, 2013, 09:04 PM
lhon12006 lhon12006 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 56 lhon12006 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 15 h 12 m 50 sec
Reputation Power: 0
thanks for this sir .. i use it .... for now .. in my project ..

Reply With Quote
  #4  
Old February 20th, 2013, 03:15 AM
diyaots diyaots is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2011
Posts: 119 diyaots Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 40 m 11 sec
Reputation Power: 0
Try this demo code

Hi try this demo:

Code:
import*java.awt.event.ActionEvent;
import*java.awt.event.InputEvent;
import*java.awt.event.KeyEvent;
import*javax.swing.AbstractAction;
import*javax.swing.Action;
import*javax.swing.ActionMap;
import*javax.swing.InputMap;
import*javax.swing.JButton;
import*javax.swing.JComponent;
import*javax.swing.JFrame;
import*javax.swing.KeyStroke;
public*class*KeyStrokeSampleVKF4Shift*{
**public*static*void*main(String[]*a)*{
****String*ACTION_KEY*=*"theAction";
****JFrame*frame*=*new*JFrame("KeyStroke*Sample");
****frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
****JButton*buttonA*=*new*JButton("<html><center>ANCESTOR<br>VK_F4+SHIFT_MASK");
****Action*actionListener*=*new*AbstractAction()*{
******public*void*actionPerformed(ActionEvent*actionEvent)*{
********JButton*source*=*(JButton)*actionEvent.getSource();
********System.out.println(source.getText());
******}
****};
****KeyStroke*shiftF4*=*KeyStroke.getKeyStroke(KeyEvent.VK_F4,*InputEvent.SHIFT_MASK);
****InputMap*inputMap*=*buttonA.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
****inputMap.put(shiftF4,*ACTION_KEY);
****ActionMap*actionMap*=*buttonA.getActionMap();
****actionMap.put(ACTION_KEY,*actionListener);
****buttonA.setActionMap(actionMap);
****frame.add(buttonA);
****frame.setSize(400,*200);
****frame.setVisible(true);
**}
}


Note:
KeyStroke*shiftF4*=*KeyStroke.getKeyStroke(KeyEvent.VK_F4,*InputEvent.SHIFT_MASK);

Last edited by diyaots : February 20th, 2013 at 03:20 AM.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Help Opening New Class

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap