1 year ago
#185946
Manish
How to take an input from a banner displayed inside a Jframe
I am working on a springboot standalone application which toggles b/w display and hiding a banner based on some situation.
Now I have got some requirement to enable the user to remove that banner by entering some pin or password as an exception to toggle logic.
I am wondering is it feasible that I can create a textfield inside the jframe or inside html page that's being displayed in JFrame to take the user input (I know html page can't be submitted) or do I need to change html to jsp or something else ?
Please suggest.
Code:
public class BringUpFrame {
static Logger logger = LoggerFactory.getLogger(BringUpFrame.class);
private static final int SWP_NOSIZE = 0x0001;
private static final int SWP_NOMOVE = 0x0002;
private static final int TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
private static final HWND HWND_TOPMOST = new HWND(Pointer.createConstant(-1));
private static JFrame frmOpt;
private static String hostname;
public static JFrame ShowBanner() throws IOException {
int width = 0;
int height = 0;
String urlText = null;
String ScrnResol = getScreenResolution();
String[] ScreenResolution = ScrnResol.split(",");
try {
width = Integer.parseInt(ScreenResolution[0]);
height = Integer.parseInt(ScreenResolution[1]);
} catch (NumberFormatException nfe) {
logger.error("NumberFormatException: " + nfe.getMessage());
}
//Creating Frame
frmOpt = new JFrame("Banner");
frmOpt.setExtendedState(JFrame.MAXIMIZED_BOTH);
frmOpt.setPreferredSize(new Dimension(width, height));
frmOpt.setUndecorated(true);
frmOpt.setBackground(new Color(1.0f, 1.0f, 1.0f, 0.1f));
frmOpt.setVisible(true);
frmOpt.setAlwaysOnTop(true);
frmOpt.setLocationRelativeTo(null);
//bringToForeground(getHWND(frmOpt));
JPanel panel = new JPanel();
LayoutManager layout = new FlowLayout();
panel.setLayout(layout);
JEditorPane jEditorPane = new JEditorPane();
jEditorPane.setEditable(false);
try {
String urlText=IOUtils.toString(BringUpFrame.class.getClassLoader().getResourceAsStream("banner.htm"));
jEditorPane.setContentType("text/html");
jEditorPane.setText(urlText);
} catch (Exception e) {
logger.error("Exception while executing showBanner: {}", e);
jEditorPane.setContentType("text/html");
jEditorPane.setText("<html>Page not found.</html>");
}
JScrollPane jScrollPane = new JScrollPane(jEditorPane);
jScrollPane.setPreferredSize(new Dimension(width, height));
panel.add(jScrollPane);
frmOpt.add(panel);
frmOpt.pack();
frmOpt.setVisible(true);
return frmOpt;
}
public static void disposeBanner() {
frmOpt.dispose();
logger.info("Banner Closed");
}
private static void bringToForeground(HWND clientWindow) {
User32Ext.INSTANCE.SetWindowPos(clientWindow, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
}
private static HWND getHWND(Component comp) {
return new HWND(Native.getComponentPointer(comp));
}
public static String getScreenResolution() {
GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int width = gd.getDisplayMode().getWidth();
int height = gd.getDisplayMode().getHeight();
String resolution = width + "," + height;
logger.info("Screen Resolution is (width,height) : " + resolution);
return resolution;
}
}
Currently banner is looking like below:
Thanks,
java
spring-boot
swing
jtextfield
jeditorpane
0 Answers
Your Answer