mainFrame.addWindowListener(new WindowListener() {
@Override
public void windowClosing(WindowEvent e) {
if (JOptionPane.showConfirmDialog(mainFrame, "Are you sure you want to quit?", "Confirm exit.", JOptionPane.OK_OPTION, 0, new ImageIcon("")) != 0) {
return;
}
System.exit(-1);
}
@Override
public void windowOpened(WindowEvent e) {}
@Override
public void windowClosed(WindowEvent e) {}
@Override
public void windowIconified(WindowEvent e) {}
@Override
public void windowDeiconified(WindowEvent e) {}
@Override
public void windowActivated(WindowEvent e) {}
@Override
public void windowDeactivated(WindowEvent e) {}
});
Run Code Online (Sandbox Code Playgroud)
有我的代码,是否可能,因为我只使用windowClosing方法删除我的情况下的所有其他方法,无用的方法,所以它占用更少的空间?
例
mainFrame.addWindowListener(new WindowListener() {
@Override
public void windowClosing(WindowEvent e) {
if …Run Code Online (Sandbox Code Playgroud) 我一直在调整 CSS 几个小时,但我已经放弃了。我不知道如何删除选项卡顶部的间距。请帮忙!
CSS:
.tab-pane {
-fx-tab-min-height: 3em;
/* 24 */
-fx-tab-max-height: 3em;
/* 24 */
}
.tab .tab-label {
-fx-background-color: transparent;
-fx-alignment: CENTER;
-fx-text-fill: #EBEAF0;
}
.tab {
-fx-background-insets: 0.0;
-fx-background-radius: 0.0;
-fx-background-color: #17181B;
}
.tab:selected {
-fx-background-color: #21477A;
}
.tab:focused {
-fx-focus-color: transparent;
}
.tab {
-fx-padding: 0 30 0 30;
}
.tab-pane *.tab-header-background {
-fx-background-color: #17181B;
}
.tab-pane:top *.tab-header-area {
-fx-background-insets: 0, 0 0 1 0;
-fx-padding: 0.416667em 0.166667em 0.0em 0.0em;
}
.tab:selected .focus-indicator {
-fx-focus-color: transparent; …Run Code Online (Sandbox Code Playgroud) 这是绘制GUI的地方(注意,该类扩展了JFrame).
public Cache() {
SubstanceColorChooserUI col = new SubstanceColorChooserUI();
while (mode == 0);
setResizable(false);
setTitle("Cache");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 483, 374);
setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(new BorderLayout());
textField = new JTextField();
textField.setBounds(10, 11, 328, 20);
contentPane.add(textField);
textField.setColumns(10);
JButton btnLoadCache = new JButton("Load cache");
btnLoadCache.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
try {
String loc = textField.getText();
if (loc.equals("")) {
JOptionPane.showMessageDialog(Cache.this, "Please specify a location for the cache.", "Unable to load", JOptionPane.ERROR_MESSAGE);
return;
} …Run Code Online (Sandbox Code Playgroud) 我正在制作一个用Java编辑图像的程序.我想知道是否可以将图像从用户桌面拖到JPanel图像上,然后将拖动的图像设置为背景JPanel.这可能在Java中吗?如果是这样,我该怎么做?
我正在尝试将JProgressBar添加到我的程序中,但它不会更新!只有在100%的原因后,该值才会更改.这是我的方法.
public void downloadImages(List<String> images) {
if (errorCode == 0) {
for (int i = 0; i < images.size(); i++) {
if (errorCode == 0) {
main.progressLabel.setText("Downloading image " + Integer.toString(i + 1) + " of " + Integer.toString(images.size()));
String imageStr = images.get(i);
String imageName = imageStr.substring(imageStr.lastIndexOf("/") + 1);
try {
URL url = new URL(imageStr);
InputStream in = url.openStream();
OutputStream out = new FileOutputStream(saveDirectory + imageName);
byte[] b = new byte[2048];
int length;
while ((length = in.read(b)) != -1) …Run Code Online (Sandbox Code Playgroud) 我试图在我的主页上写一些代码来检查用户是否登录。这是代码块
<div class="navbar-collapse collapse">
<asp:LoginView runat="server" ViewStateMode="Disabled">
<%
if (Session["UserID"] == null) {
%>
<AnonymousTemplate>
<ul class="nav navbar-nav navbar-right">
<li><a runat="server" href="~/Account/Register">Register</a></li>
<li><a runat="server" href="~/Account/Login">Log in</a></li>
</ul>
</AnonymousTemplate>
<%
} else {
%>
<LoggedInTemplate>
<ul class="nav navbar-nav navbar-right">
<li><a runat="server" href="~/Account/Manage" title="Manage your account">Hello, <%: Session["UserID"] %>!</a></li>
<li>
<asp:LoginStatus runat="server" LogoutAction="Redirect" LogoutText="Log off" LogoutPageUrl="~/" OnLoggingOut="Unnamed_LoggingOut" />
</li>
</ul>
</LoggedInTemplate>
<%
}
%>
</asp:LoginView>
</div>
Run Code Online (Sandbox Code Playgroud) 我开始对使用Java制作动画(幻灯片,背景等)感兴趣.我知道JavaFX做得好多了,但我只是顽固地打扰转换.
这是我到目前为止所得到的.
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.awt.image.BufferedImageOp;
import java.awt.image.ConvolveOp;
import java.awt.image.Kernel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class BlurredLightCells extends JPanel {
private static final long serialVersionUID = 4610174943257637060L;
private Random random = new Random();
private ArrayList<LightCell> lightcells;
private float[] blurData = new float[500];
public static void main(String[] args) {
JFrame frame = new JFrame("Swing animated bubbles");
frame.setSize(1000, 750);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new BlurredLightCells(60));
frame.setVisible(true);
}
public BlurredLightCells(int amtOfBCells) { …Run Code Online (Sandbox Code Playgroud) 从字节数组创建String时遇到问题,在构造字符串时忽略数组内的0值.我怎样才能使它如果字节值为0,String只是添加一个空格而不是删除它.
例如,这是输出DT_TestTracelineCTestTraceli.
public static void main(String[] args) {
byte[] text = {68, 84, 95, 84, 101, 115, 116, 84, 114, 97, 99, 101, 108, 105, 110, 101, 0, 0, 0, 0, 67, 84, 101, 115, 116, 84, 114, 97, 99, 101, 108, 105};
System.out.println(new String(text));
}
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做,所以我可以使用制表符分隔这两个字符串或使用空格,以便输出 DT_TestTraceline CTestTraceli
谢谢
可能重复:
Python中的三元条件运算符
我已经用Java编程了很长一段时间,我在学校学习Python,我记得在Java中你可以做一个布尔表达式
布尔值?(如果布尔值为true,则会发生这种情况):(如果布尔值为false,则会发生这种情况)
他们是用Python编写上述Java代码的方法吗?上面的陈述恰当地称为什么?
好吧,我正在为我的服务器制作一个客户端并且JMenu工作正常,直到我添加了applet,现在当我点击菜单查看下拉菜单时,它没有显示.我假设它隐藏在applet后面,但我无法解决它
public class Loader extends JApplet implements Serializable, ActionListener {
private static final long serialVersionUID = 7639088664641445302L;
private static final HashMap<String, String> THEME_LIST = new HashMap<String, String>();
private final String[] THEME_NAMES = { "Magma", "Emerald", "Raven", "Black Steel", "Challenger", "Sahara", "Silver", "Blue" };
public Properties params = new Properties();
public JFrame mainframe;
public JPanel mainpanel = new JPanel();
public static boolean useIsaac = false;
private static Robot robot;
private static final String HOME = System.getProperty("user.home") + "\\";
public …Run Code Online (Sandbox Code Playgroud) 所以今天我了解了kotlin中的num.inc()功能,并决定在我的代码中实现它.不用说,这为我的代码增加了10倍的延迟时间(从~400ms到4000 + ms)
这是我传统方式的例子(i ++,400ms)
package com.beaudoin
import java.io.BufferedWriter
import java.io.FileInputStream
import java.io.FileWriter
import java.nio.channels.FileChannel
fun main(args: Array<String>) {
val s = System.currentTimeMillis()
val channel = FileInputStream("client.dll").channel
val buffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size())
val data = ByteArray(buffer.capacity())
buffer.get(data)
val writer = BufferedWriter(FileWriter("dump.txt", false))
val bytes = ByteArray(16)
var offset = 0
var i = 0
while (i < data.size) {
for (j in bytes.indices) {
bytes[j] = data[i++]
}
writer.write(HexRow(offset, bytes).toString())
writer.newLine()
offset += 16
}
writer.close()
println(System.currentTimeMillis() - s) …Run Code Online (Sandbox Code Playgroud) java ×9
swing ×6
animation ×1
arrays ×1
asp.net ×1
boolean ×1
c# ×1
components ×1
concurrency ×1
css ×1
expression ×1
image ×1
japplet ×1
javafx ×1
jframe ×1
jmenu ×1
joptionpane ×1
jpanel ×1
jprogressbar ×1
kotlin ×1
python ×1
resize ×1
string ×1