我在创建散点图的屏幕截图时遇到问题.我的屏幕截图始终包含黑框.
这是我的XAML代码:
<s:SurfaceWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="http://schemas.microsoft.com/surface/2008"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="MakeScreenshots.SurfaceWindow1"
Title="MakeScreenshots" Width="1000" Height="700"
>
<s:SurfaceWindow.Resources>
<ImageBrush x:Key="WindowBackground" Stretch="None" Opacity="0.6" ImageSource="pack://application:,,,/Resources/WindowBackground.jpg"/>
</s:SurfaceWindow.Resources>
<Grid x:Name="GlobalGrid" Background="{StaticResource WindowBackground}" Width="1000" Height="700" >
<s:ScatterView x:Name="ScatterViewScreenShot" Margin="108,89,176,73" Width="700" Height="500">
<s:ScatterView.Background>
<SolidColorBrush Color="{DynamicResource {x:Static SystemColors.ActiveCaptionColorKey}}"/>
</s:ScatterView.Background>
<s:ScatterViewItem Margin="0,-26.953,-130.946,-23.047" Content="ScatterViewItem 3" HorizontalAlignment="Right" Width="125.826"/>
<s:ScatterViewItem Margin="0,0,-490.513,-151.256" HorizontalAlignment="Right" Width="125.77" Height="60.427" VerticalAlignment="Bottom" Content="ScatterViewItem 2"/>
<s:ScatterViewItem Content="ScatterViewItem 1" Margin="-331.43,0,0,-129.589" HorizontalAlignment="Left" Width="177.949" Height="67.905" VerticalAlignment="Bottom"/>
</s:ScatterView>
<Button x:Name="MakeScreenShotButton" Click="MakeScreenShotButton_Click" Content="MakeScreenShot" Margin="267,17,343,0" VerticalAlignment="Top" Height="38.96"/>
<Button Content="MakeScreenShotButton2" Height="39" HorizontalAlignment="Left" Margin="116,614,0,0" Name="button1" VerticalAlignment="Top" Width="301" Click="MakeScreenShotButton2_Click" />
<Button …Run Code Online (Sandbox Code Playgroud) 究竟是什么导致了这个?我正在尝试在java程序中创建的一个方法上遇到两个相互矛盾的错误
public void numberOfTrianglesIncidentToVertex(){
for(List<Integer> pairs: neighbors.get(2)){ // Type mismatch: cannot convert from element type Integer to List<Integer>
}
int fail = neighbors.get(2); // Type mismatch: cannot convert from List<Integer> to int
}
Run Code Online (Sandbox Code Playgroud)
neighbor变量在超类中声明如下:
List<List<Integer>> neighbors
= new ArrayList<List<Integer>>();
Run Code Online (Sandbox Code Playgroud)
我不知道为什么它会在一行上告诉我它是一个整数并且不能转换为整数列表然后在下一行只是改变它的想法并说出完全相反的意思.这是什么?
我已经看过关于这个主题的其他帖子,但他们找到的解决方案并不适用于我.我正在设置加权值并使用c.fill = GridBagConstraints.BOTH约束.
我包含了我所拥有的整个GUI代码,以防我的错误来自GridBagLayout以外的其他东西.
我想要右边的可滚动文本块来扩展GUI中的剩余空间,并且我已经设置了应该归因于它的所有变量,但它仍然无法正常工作.我究竟做错了什么?
我的结果:

import java.awt.*;
import javax.swing.*;
public class TestCode extends JFrame {
JTextArea textArea = new JTextArea ();
JComboBox <String> typeComboBox;
JTextField searchField;
JTextField fileField;
public TestCode(){
setTitle ("GUI Test");
setSize (600, 300);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
JScrollPane scrollPane = new JScrollPane(textArea);
JButton readButton = new JButton("Read File");
JButton displayButton = new JButton("Display");
JButton searchButton = new JButton("Search");
searchField = new JTextField(10);
fileField = new JTextField(15);
typeComboBox = new JComboBox <String> ();
typeComboBox.addItem("Index");
typeComboBox.addItem("Type"); …Run Code Online (Sandbox Code Playgroud) bootstrap CSS中有错误吗?我试图使用默认的bootstrap下拉菜单和拆分按钮,但侧面的向下箭头按钮比实际菜单短得多.
我认为这是我的代码中的一些重叠样式问题,但我设法使用JSFiddle中的boostrap代码重现这一点.
<div class="btn-group">
<button type="button" class="btn btn-danger">Action</button>
<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<span class="sr-only">Toggle Dropdown</span>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Separated link</a>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我确信这是string.replaceAll()方法如何工作的产物,但是由于一些奇怪的原因,当你键入任何带有空格的东西时,它会使我的循环运行两次?
public class TestCode{
public static void main(String[] args) throws IOException{
Scanner scan = new Scanner(System.in);
String input = "";
while(!input.equals("X")){
System.out.println("Prompt user for input");
input = scan.next().toUpperCase();
calculatePolynomial(input);
}
}
public static void calculatePolynomial(String input){
//Clean up entry removing spaces and extracting polynomial names
String calculation = input.replaceAll("\\s", "");
System.out.println(calculation);
}
}
Run Code Online (Sandbox Code Playgroud)
想法是让代码运行...打印出消息,提示输入.然后处理输入并做一些事情.反复重复该过程,直到输入标记值"x".
但是当你输入包含空格的输入时,由于某种原因,它会运行循环,就像每个单词现在是单独的输入一样.因此,如果您输入三个单词,它只会运行循环三次而不是一次.
我只是希望用户的输入没有空格而且没有逻辑错误的噩梦.
我已经看到类似的问题,询问如何找到一个空白行.我知道如何找到一个空白行,但找到它的绝对性质会检索它并搞砸其余的代码.
考虑以下while循环:
while(file.hasNextLine()){
if(file.nextLine.equals("")){
continue;
}
String[] words = file.nextLine().split(" ");
for(int i = 0; i < words.length; i++){
System.out.print(words[i]);
}
}
Run Code Online (Sandbox Code Playgroud)
这里的想法是,如果有一个空行,跳过这个迭代并移动到下一行只提取单词.但只是检查线是否为空检索下一行(空白或不空白),然后检索FOLLOWING行并将其存储为单词.
在没有实际检索'nextLine'的情况下找到空白行的正确方法是什么?
我正在尝试做一个简单的编程挑战,而且我遇到了一个与Math.pow()函数有关的奇怪和无关的问题.
我得到6的1的力量是54?
我正在读取在命令行输入的文件(通过args [0]).该文件只包含三个数字:
6
75
153
Run Code Online (Sandbox Code Playgroud)
我正在运行的程序如下:
public static void main (String[] args)throws IOException{
File filename = new File(args[0]);
Scanner file = new Scanner(filename);
while(file.hasNextLine()){
String numbers = file.nextLine();
int numValue = Integer.parseInt(numbers);
int sumOfPowers = 0;
for(int i = 0; i < numbers.length(); i++){
sumOfPowers += Math.pow(numbers.charAt(i), numbers.length());
System.out.println(Math.pow(numbers.charAt(i), numbers.length()));
System.out.println(Math.pow(6, 1));
}
}
file.close();
}
Run Code Online (Sandbox Code Playgroud)
这产生的输出是奇数.基于这些类型的值创建幂函数是否违反Java规则?
输出我得到:
54.0
6.0
3025.0
6.0
2809.0
6.0
117649.0
6.0
148877.0
6.0
132651.0
6.0
Run Code Online (Sandbox Code Playgroud) 我开始认为我不像我想的那样理解多态性.
我有以下情况:
public class Testing {
public static void main(String[] args){
interTest myTest = new classTest();
myTest.classMethod();
}
}
Run Code Online (Sandbox Code Playgroud)
使用给定的界面:
public interface interTest {
public boolean checkBoolean();
public void method();
}
Run Code Online (Sandbox Code Playgroud)
然后是具体的课程:
public class classTest implements interTest{
public classTest() {
// TODO Auto-generated constructor stub
}
public void classMethod(){
System.out.println("fail");
}
// Both method() and checkBoolean() are overridden here & do nothing.
}
}
Run Code Online (Sandbox Code Playgroud)
Oracle文档演示了如何实现接口然后添加其他方法,甚至实现多个接口(因此包括不在其中一个接口中的方法),我认为这很常见,直到我遇到试图自己尝试这样做的问题.
在这种情况下,我无法访问,classMethod因为它不在界面内.
The method classMethod() is undefined for the type interTest
Run Code Online (Sandbox Code Playgroud)
我对多态性的理解是什么?我想在表单中声明一个变量:
Interface object …Run Code Online (Sandbox Code Playgroud) 我试图创建一个看起来和感觉像<a>标签项的链接,但运行一个函数而不是使用href。
当我尝试将onclick函数应用于链接时,无论该链接从未被单击过,它都会立即调用该函数。此后任何尝试单击链接的尝试都会失败。
我究竟做错了什么?
的HTML
<div id="parent">
<a href="#" id="sendNode">Send</a>
</div>
Run Code Online (Sandbox Code Playgroud)
Java脚本
startFunction();
function secondFunction(){
window.alert("Already called!?");
}
function startFunction() {
var sentNode = document.createElement('a');
sentNode.setAttribute('href', "#");
sentNode.setAttribute('onclick', secondFunction());
//sentNode.onclick = secondFunction();
sentNode.innerHTML = "Sent Items";
//Add new element to parent
var parentNode = document.getElementById('parent');
var childNode = document.getElementById('sendNode');
parentNode.insertBefore(sentNode, childNode);
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我尝试了两种添加此onclick函数的不同方法,两种方法都具有相同的效果。
我想通过j-query和Java脚本简单代码删除特定选择框的所有未选择的选项
示例:如果我选择第一个选择框的test-1选项,那么所有未选择的选项都将被删除,并且此条件适用于所有选择框
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<select class="mymultiSelect" onchange="myfun()">
<option value="0">-select-</option>
<option value="1">test - 1</option>
<option value="2">test - 2</option>
<option value="3">test - 3</option>
<option value="4">test - 4</option>
</select>
<select class="mymultiSelect" onchange="myfun()">
<option value="0">-select-</option>
<option value="1">test - 1</option>
<option value="2">test - 2</option>
<option value="3">test - 3</option>
<option value="4">test - 4</option>
</select>
<select class="mymultiSelect" onchange="myfun()">
<option value="0">-select-</option>
<option value="1">test - 1</option>
<option value="2">test - 2</option>
<option value="3">test - 3</option>
<option value="4">test - 4</option>
</select>
<select class="mymultiSelect" onchange="myfun()">
<option value="0">-select-</option>
<option value="1">test - 1</option>
<option …Run Code Online (Sandbox Code Playgroud)java ×6
html ×2
css ×1
file ×1
frame ×1
html-select ×1
interface ×1
javascript ×1
jquery ×1
jscrollpane ×1
math ×1
methods ×1
onclick ×1
polymorphism ×1
pow ×1
replace ×1
scatterview ×1
scope ×1
screenshot ×1
string ×1
swing ×1
uielement ×1
while-loop ×1
wpf ×1