- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 Java 很陌生,对 NetBeans 甚至还比较陌生。我只是不知道如何解决这个问题。
当我运行我的项目时,GUI 最初不显示。应该有一个带有下拉菜单的菜单栏,用于打开和保存文件以及退出程序。窗口底部还应该有三个按钮,可用于显示文件中的数据(在本例中为图像)。但相反,当您运行程序时,窗口是空白的,什么也没有显示。
当我单击左上角"file"位于菜单栏上的位置时,它就会显示出来,并且顶部按钮也会在此时显示。后两个按钮应显示为灰色,并且只有在单击第一个按钮并显示第一张图像后才可单击。
我尝试寻找解决方案,并摆弄 NetBeans 设置,但似乎无法解决此问题。我假设这与一些东西被错误地放置在前景或背景有关,但我不确定。
另外,我发现如果我删除代码中的drawImage位((public void Paint (Graphics g) {g.drawImage(imageToPaint, 50, 70, this);}),那么GUI就会出现,所以我我猜这与某些地方有冲突?!
如果有人能对此有所了解,请提前致谢!
package final_project;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.MemoryImageSource;
import java.util.*;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
public abstract class Analyst extends javax.swing.JFrame
implements ActionListener {
double heights[][] = new double [300][300];
double grads[][] = new double [300][300];
double tempg[] = new double [8];
double wgrads[][] = new double [300][300];
Image imageToPaint;
public boolean shouldcolourheights = false;
int blue = 1;
int green = 1;
int red = 1;
public Analyst() {
initComponents();
}
public double [][] convertFromString(String[] stArray){
double[][] data = new double [300][300];
int lines = stArray.length;
for (int i = 0; i<lines; i++){
StringTokenizer st = new StringTokenizer(stArray[i]," ");
int j=0;
while (st.hasMoreTokens()){
data[i][j]=Double.parseDouble(st.nextToken());
j++;
}
}
return data;
}
double[] get1DArray (double[][] twoDarray) {
double[] tempArray = new double[twoDarray.length * twoDarray[0].length];
for (int i = 0; i < twoDarray.length; i++) {
for (int j = 0; j < twoDarray[i].length; j++) {
tempArray[(i * twoDarray[0].length) + j] = twoDarray[i][j];
}
}
return tempArray;
}
public double getMaxGrad (int bound){
double maxgrad = 0.0;
for (int k=0; k<bound; k++){
if (tempg[k]>maxgrad){
maxgrad=tempg[k];
}
}
return maxgrad;
}
public Image getImage (double [][] array) {
int arrayW = array[0].length;
int [] pixels = new int [array.length * arrayW];
double [] oneDim = get1DArray(array);
for (int i = 0; i < pixels.length; i++) {
int value = (int) oneDim[i];
if (value > 255){
value = 255;
}
if (shouldcolourheights){
int newi = (int) Math.floor(i/300);
int newj = (int) i-(newi*300);
if (grads[newi][newj] < 1.0){
blue=1; green=1; red=1;
} else if (grads[newi][newj] <=1.5) {
blue=0; red=0; green=1;
} else if (grads[newi][newj] <=3.0) {
blue=1; red=0; green=0;
} else {blue=0; red=1; green=0;}
}
Color pixel;
pixel = new Color(value * red, value * green, value * blue, 255);
pixels[i] = pixel.getRGB();
}
MemoryImageSource memImage = new MemoryImageSource(arrayW,arrayW,pixels,0,arrayW);
Panel p = new Panel();
Image image = p.createImage(memImage);
return image;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
fc = new javax.swing.JFileChooser();
btnHeights = new javax.swing.JButton();
btnGradients = new javax.swing.JButton();
btnColourH = new javax.swing.JButton();
jMenuBar = new javax.swing.JMenuBar();
jMenu = new javax.swing.JMenu();
jMenuOpen = new javax.swing.JMenuItem();
jMenuSave = new javax.swing.JMenuItem();
jSeparator = new javax.swing.JPopupMenu.Separator();
jMenuExit = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
btnHeights.setText("Heights");
btnHeights.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnHeightsActionPerformed(evt);
}
});
btnGradients.setText("Gradients");
btnGradients.setEnabled(false);
btnGradients.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGradientsActionPerformed(evt);
}
});
btnColourH.setText("Colour Heights");
btnColourH.setEnabled(false);
btnColourH.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnColourHActionPerformed(evt);
}
});
jMenu.setText("File");
jMenuOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
jMenuOpen.setText("Open");
jMenuOpen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuOpenActionPerformed(evt);
}
});
jMenu.add(jMenuOpen);
jMenuSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
jMenuSave.setText("Save");
jMenuSave.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuSaveActionPerformed(evt);
}
});
jMenu.add(jMenuSave);
jMenu.add(jSeparator);
jMenuExit.setText("Exit");
jMenuExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuExitActionPerformed(evt);
}
});
jMenu.add(jMenuExit);
jMenuBar.add(jMenu);
setJMenuBar(jMenuBar);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(btnColourH, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnGradients, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnHeights, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap(258, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(381, Short.MAX_VALUE)
.addComponent(btnHeights)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnGradients)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnColourH)
.addGap(27, 27, 27))
);
pack();
}// </editor-fold>
private void jMenuOpenActionPerformed(java.awt.event.ActionEvent evt) {
FileFilter ft = new FileNameExtensionFilter("Text Files", "txt");
fc.addChoosableFileFilter(ft);
int returnVal = fc.showOpenDialog(this);
if (returnVal==javax.swing.JFileChooser.APPROVE_OPTION) {
java.io.File file = fc.getSelectedFile();
String file_name = file.toString();
try {
ReadFile file_read = new ReadFile(file_name);
String [] arraylines = file_read.OpenFile();
heights = convertFromString(arraylines);
}
catch (java.io.IOException e) {
JOptionPane.showMessageDialog(Analyst.this, "File does not exist");
}
}
}
private void jMenuSaveActionPerformed(java.awt.event.ActionEvent evt) {
String tempStr = "";
FileFilter ft = new FileNameExtensionFilter("Text Files", "txt");
fc.addChoosableFileFilter(ft);
int returnVal = fc.showSaveDialog(this);
if (returnVal==javax.swing.JFileChooser.APPROVE_OPTION) {
java.io.File saved_file = fc.getSelectedFile();
String file_name = saved_file.toString();
try {
WriteFile dataOut = new WriteFile(file_name, true);
for (int i=0; i<grads.length; i++) {
for (int j=0; j<grads[i].length; j++){
double rgrad = Math.floor(grads[i][j] * 10) / 10;
tempStr = tempStr + String.valueOf(rgrad) +" ";
}
dataOut.writeToFile(tempStr);
tempStr = "";
}
}
catch (java.io.IOException e) {
JOptionPane.showMessageDialog(Analyst.this, "File not written");
}
}
repaint();
}
private void jMenuExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void btnHeightsActionPerformed(java.awt.event.ActionEvent evt) {
shouldcolourheights=false;
red=1; blue=1; green=1;
imageToPaint = getImage(heights);
repaint();
btnGradients.setEnabled(true);
}
private void btnGradientsActionPerformed(java.awt.event.ActionEvent evt) {
double root2 = Math.sqrt(2.0);
double scaling = 1.0; //cells of 1m assumed
double weighting = 40.0; //to give more defined image
//The 8 neighbour cells
for (int i=1; i<299; i++) {
for (int j=1; j<299; j++){
tempg[0] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
tempg[1] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
tempg[3] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
tempg[4] = Math.abs(heights[i][j-1]-heights[i][j]);
tempg[5] = Math.abs(heights[i-1][j]-heights[i][j]);
tempg[6] = Math.abs(heights[i][j+1]-heights[i][j]);
tempg[7] = Math.abs(heights[i+1][j]-heights[i][j]);
grads[i][j] = getMaxGrad(8)/scaling;
}
}
//The 5 neighbour cells
int i=0;
for (int j=1; j<299; j++) {
tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
tempg[1] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i+1][j]-heights[i][j]);
tempg[3] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
tempg[4] = Math.abs(heights[i][j+1]-heights[i][j]);
grads[i][j] = getMaxGrad(5)/scaling;
}
i=299;
for (int j=1; j<299; j++){
tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
tempg[1] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i-1][j]-heights[i][j]);
tempg[3] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
tempg[4] = Math.abs(heights[i][j+1]-heights[i][j]);
grads[i][j] = getMaxGrad(5)/scaling;
}
int j=0;
for (i=1; i<299; i++){
tempg[0] = Math.abs(heights[i-1][j]-heights[i][j]);
tempg[1] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i][j+1]-heights[i][j]);
tempg[3] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
tempg[4] = Math.abs(heights[i+1][j]-heights[i][j]);
grads[i][j] = getMaxGrad(5)/scaling;
}
j=299;
for (i=1; i<299; i++){
tempg[0] = Math.abs(heights[i+1][j]-heights[i][j]);
tempg[1] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i][j-1]-heights[i][j]);
tempg[3] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
tempg[4] = Math.abs(heights[i-1][j]-heights[i][j]);
grads[i][j] = getMaxGrad(5)/scaling;
}
//The 3 neighbour cells
i=0; j=0;
tempg[0] = Math.abs(heights[i+1][j]-heights[i][j]);
tempg[1] = Math.abs(heights[i+1][j+1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i][j+1]-heights[i][j]);
grads[i][j] = getMaxGrad(3)/scaling;
i=299; j=0;
tempg[0] = Math.abs(heights[i-1][j]-heights[i][j]);
tempg[1] = Math.abs(heights[i-1][j+1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i][j+1]-heights[i][j]);
grads[i][j] = getMaxGrad(3)/scaling;
i=0; j=299;
tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
tempg[1] = Math.abs(heights[i+1][j-1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i+1][j]-heights[i][j]);
grads[i][j] = getMaxGrad(3)/scaling;
i=299; j=299;
tempg[0] = Math.abs(heights[i][j-1]-heights[i][j]);
tempg[1] = Math.abs(heights[i-1][j-1]-heights[i][j])/root2;
tempg[2] = Math.abs(heights[i-1][j]-heights[i][j]);
grads[i][j] = getMaxGrad(3)/scaling;
//grads holds the actual 'D8' gradients and is to be written to
//a file. In order to display greyscale image the values need to be
//weighted up (grads is left unchanged).
//
for (i=0; i<300; i++) {
for (j=0; j<300; j++){
wgrads[i][j] = grads[i][j] * weighting;
}
}
shouldcolourheights=false;
red=1; blue=1; green=1;
imageToPaint = getImage(wgrads);
repaint();
jMenuSave.setEnabled(true);
btnColourH.setEnabled(true);
}
public void paint (Graphics g) {
g.drawImage(imageToPaint, 50, 70, this);
}
/**
* Redraws the height image with colour to represent the gradients.
* @param evt
*/
private void btnColourHActionPerformed(java.awt.event.ActionEvent evt) {
shouldcolourheights=true;
imageToPaint = getImage(heights);
repaint();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Analyst() {
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
}
} .setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnColourH;
private javax.swing.JButton btnGradients;
private javax.swing.JButton btnHeights;
private javax.swing.JFileChooser fc;
private javax.swing.JMenu jMenu;
private javax.swing.JMenuBar jMenuBar;
private javax.swing.JMenuItem jMenuExit;
private javax.swing.JMenuItem jMenuOpen;
private javax.swing.JMenuItem jMenuSave;
private javax.swing.JPopupMenu.Separator jSeparator;
// End of variables declaration
}
最佳答案
添加super.paint(g)
。
@Override
public void paint(Graphics g) {
super.paint(g);
g.drawImage(imageToPaint, 50, 70, this);
}
您还可以使用System.arraycopy
来加快复制速度。
double[] get1DArray(double[][] twoDarray) {
double[] tempArray = new double[twoDarray.length * twoDarray[0].length];
int jdim = twoDarray[0].length;
for (int i = 0; i < twoDarray.length; i++) {
System.arraycopy(twoDarray[i], 0, tempArray, i * jdim, jdim);
}
return tempArray;
}
关于java - GUI 最初未显示(netbeans),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16339009/
我有一个使用 Sinch SDK 和 CallKit 实现的 VOIP 应用程序。一切正常,除了设备插入耳机时。在后一种情况下,当通话开始时,音频仍通过设备的主扬声器路由。如果我在通话期间拔下并重
我需要将大量复杂(20 多个属性)对象过滤成多个子列表。要创建子列表,我有一个过滤器规范列表。要求是:a) 不允许一个项目成为两个子列表的一部分,并且 b) 必须能够在处理完成后获取所有未分割的项目。
我有一个简单的 .share-toggle 切换链接。当您点击它时,Facebook 评论插件应该会显示。它最初应该被 Conceal 问题是,如果我使用 css Conceal 它,然后单击切换按钮
我正在尝试制作一个功能类似于 android 市场的图库,您可以在其中滚动(左/右)以查看免费或付费应用程序等...还可以在布局中上下滚动。 到目前为止,我只是让它加载了两个布局,它们都有一个简单的“
大家好,我是网络开发的新手,最近刚刚完成我对网络设计的第一次尝试。我偶然发现了一个我找不到解决方案的问题。在 webkit-browsers 中,我的一个 ul-lists(导航)最初呈现在错误的位置
我遇到了这个问题。我在 ISP 上使用 Umbraco CMS 启动了一个 ASP.NET 网站。(这只是一个非常基本的信息网站。没什么特别的。) 但是,当我想要访问该网站时,第一个页面加载需要很长时
在我的 iPhone 应用程序中,我使用 UITabBarController 布置了三个选项卡。第一个选项卡(在应用启动时加载)使用本地数据加载,速度非常快。 虽然第二个选项卡从网络下载 XML 文
我有这样的风格: #cytoscape-container { width: 100%; height: 100%; margin: 0 aut
我在这里看到了几篇关于 SO 的帖子,但它们在功能和结构上过于具体,而我正在寻找的是我或任何人都可以在任何地方使用的更通用的东西。 我只需要有一个按钮,单击该按钮可以在 3 类之间循环。但如果出现必须
我在 http://www.raven.dima.neoturbine.net/ 有一个网页我正在努力。顶部导航在 IE 8、Firefox 3.6 和适用于 Android 的 Dolphin 浏览
我想将主机的用户/组与 docker 机器同步,以使(开发人员)能够编辑容器内部或外部的文件。有一些这样的想法:Handling Permissions with Docker Volumes这会创建
向通知列表/栏发布推送通知时,.contentText 和 .number 最初不显示(.ticker、.icon 和 .contentTitle 显示正常)。但是,在发布另一个通知(具有不同的 ID
我实现了以下 MKMapView 方法,该方法在添加注释后运行。我在 Interface Builder 中将我的 MKMapView map (parishMap) 设置为“显示用户位置”,并且在加
我是一名优秀的程序员,十分优秀!